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 serhiy.storchaka
Recipients Camion, eric.smith, r.david.murray, rhettinger, serhiy.storchaka, steven.daprano
Date 2017-12-10.22:54:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512946441.67.0.213398074469.issue32259@psf.upfronthosting.co.za>
In-reply-to
Content
Camion, the problem is not in the error message. The problem is in the complex expression that produces an error. If you have a complex expression you always have a change to misidentify the source of error. In your case the expression contains two implicit iter() invocations.

I have looked at the code. It is possible to make the error message in this case more specific. There are precedences of this when pass wrong type as var-positional or var-keyword arguments:

>>> print(*1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: print() argument after * must be an iterable, not int
>>> print(**1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: print() argument after ** must be a mapping, not int

In the following cases the error message is general. It is possible to make it more specific.

>>> a, b = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> [*1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> {*1}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> {**1}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not a mapping

But PyObject_GetIter() is called in 88 places in CPython core and extensions. In all these cases we can make error messages more specific. But I have large doubts that it is worth to do. And I'm not sure even about the above examples.

If somebody provide a patch we could discuss it (I'm not sure it will be accepted at end).
History
Date User Action Args
2017-12-10 22:54:01serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, eric.smith, steven.daprano, r.david.murray, Camion
2017-12-10 22:54:01serhiy.storchakasetmessageid: <1512946441.67.0.213398074469.issue32259@psf.upfronthosting.co.za>
2017-12-10 22:54:01serhiy.storchakalinkissue32259 messages
2017-12-10 22:54:01serhiy.storchakacreate