This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TypeError swallowing in UNPACK_SEQUENCE opcode
Type: Stage:
Components: None Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: djmitche, georg.brandl, pjdelport
Priority: normal Keywords: patch

Created on 2007-03-16 15:22 by pjdelport, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
UNPACK_SEQUENCE.patch pjdelport, 2007-03-16 15:22 patch against Python 2.5 (ceval.c and test_unpack.py)
Messages (4)
msg52256 - (view) Author: Piet Delport (pjdelport) Date: 2007-03-16 15:22
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'
msg52257 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-17 15:49
It's patch, after all :)
msg52258 - (view) Author: Dustin J. Mitchell (djmitche) * Date: 2007-03-19 19:29
Looks good to me.  

I've never seen software try to catch this error by string comparison, so I doubt it will break existing applications.  The worst consequence may be that various HOWTOs will now incorrectly specify the Python output -- not a big deal.
msg52259 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-21 09:01
Committed as rev. 54480, 54481 (2.5).
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44731
2007-03-16 15:22:39pjdelportcreate