Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32259>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to