Issue 5218: Check for tp_iter in ceval:ext_do_call before overriding exception message (original) (raw)

Issue5218

Created on 2009-02-11 19:32 by gpolo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
check_before_overriding.diff gpolo,2009-02-11 21:34 review
Messages (7)
msg81657 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-02-11 19:32
Hi, I find it weird that given this sample code: def g(): yield iter(None) list(*g()) I get this traceback: Traceback (most recent call last): File "a1.py", line 3, in list(*g()) TypeError: type object argument after * must be a sequence, not generator At a minimum the exception message looks awkward to me. With the proposed patch, the new traceback would be: Traceback (most recent call last): File "a1.py", line 3, in list(*g()) File "a1.py", line 2, in g yield iter(None) TypeError: 'NoneType' object is not iterable
msg81658 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-02-11 19:35
(Btw, the suggestion to check for tp_iter came from Antoine Pitrou. It seemed fine to me.)
msg81659 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-02-11 19:41
You must check tp_iter as well, not only Py_TPFLAGS_HAVE_ITER. Py_TPFLAGS_HAVE_ITER only tells you that the tp_iter field exists, not that it's non-NULL. (see the code for PyObject_GetIter() in Objects/abstract.c for an example)
msg81675 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-02-11 21:34
Thanks for taking a look, my bad for taking so long to reply. I'm adding a new patch now. This one, besides the fix needed mentioned above, disregards tp_iter from old class instances (since they are always available and tell us nothing).
msg119296 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-21 13:47
Is this ready to commit?
msg151111 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2012-01-12 04:52
See also Issue 4806
msg152581 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-02-04 02:27
This is one of 4 duplicate issues, 3 with somewhat similar patches, with nearly disjoint nosy lists. Consolidating.
History
Date User Action Args
2022-04-11 14:56:45 admin set github: 49468
2012-02-04 02:27:29 terry.reedy set status: open -> closedsuperseder: Function calls taking a generator as star argument can mask TypeErrors in the generatorversions: + Python 3.2, Python 3.3, - Python 3.1nosy: + terry.reedymessages: + resolution: duplicate
2012-01-12 04:52:43 martin.panter set nosy: + martin.pantermessages: +
2010-12-15 20:41:39 pitrou set assignee: pitrou -> nosy:georg.brandl, pitrou, gpolo
2010-10-21 13:47:47 georg.brandl set assignee: pitroumessages: + nosy: + georg.brandl
2009-02-13 17:50:47 gpolo set files: - check_tpiter_before_overriding_msg.diff
2009-02-11 21:34:32 gpolo set files: + check_before_overriding.diffmessages: +
2009-02-11 19:41:44 pitrou set nosy: + pitroumessages: +
2009-02-11 19:35:28 gpolo set messages: +
2009-02-11 19:34:18 gpolo set type: behaviorcomponents: + Interpreter Coreversions: + Python 3.1, Python 2.7
2009-02-11 19:32:42 gpolo create