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.

Author steven.daprano
Recipients Camion, eric.smith, serhiy.storchaka, steven.daprano
Date 2017-12-10.10:31:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20171210103129.GG22248@ando.pearwood.info>
In-reply-to <1512900027.91.0.213398074469.issue32259@psf.upfronthosting.co.za>
Content
On Sun, Dec 10, 2017 at 10:00:27AM +0000, Camion wrote:

> Understanding that, I suggest to simply add "(expected 'tuple')" at the end of the message.
> ex : TypeError: 'int' object is not iterable (expected 'tuple')

That is incorrect: a tuple is not expected. Any iterable (sequence, 
iterator, tuple, list, set, frozenset, dict, etc) will do. One thing we 
should not do is give a misleading, overly-specific message that implies 
only a tuple will work.

We could say 

TypeError: 'int' object is not iterable (expected iterable)

but that's redundants, since the comment in the parentheses is implied 
by the fact that *not* being iterable is an error.

I think the right thing to do here (if possible!) is to distinguish 
between unpacking and other iteration. E.g.

for x in 20: ... 
=> TypeError: 'int' object is not iterable

a, b = 20
=> TypeError: cannot unpack 'int' object (not iterable)

or similar. I'm less concerned about the exact wording than the fact 
that we give a hint that it was the unpacking operation that failed, 
rather than iteration in some other context.
History
Date User Action Args
2017-12-10 10:31:41steven.dapranosetrecipients: + steven.daprano, eric.smith, serhiy.storchaka, Camion
2017-12-10 10:31:41steven.dapranolinkissue32259 messages
2017-12-10 10:31:41steven.dapranocreate