Issue 1682205: TypeError swallowing in UNPACK_SEQUENCE opcode (original) (raw)
When UNPACK_SEQUENCE unpacks an iterable, it replaces any TypeError raised by the iterator with a new, catch-all TypeError('unpack non-sequence') instance (and empty traceback). This message is less useful than the ones it's (presumably) intended to replace (raised by PyObject_GetIter(), via unpack_iterable()), and obviously wrong when the TypeError originates in unrelated user code.
The attached patch simply removes the check, which (as far as i can tell) has no ill effects.
Examples (without the patch):
a, b, c = 7 TypeError: unpack non-sequence a, b = ( int(x) for x in ['5', ()] ) TypeError: unpack non-sequence
With the patch applied, these result in:
a, b, c = 7 TypeError: 'int' object is not iterable a, b = ( int(x) for x in ['5', ()] ) TypeError: int() argument must be a string or a number, not 'tuple'