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: Check for tp_iter in ceval:ext_do_call before overriding exception message
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator
View: 4806
Assigned To: Nosy List: georg.brandl, gpolo, martin.panter, pitrou, terry.reedy
Priority: normal Keywords: patch

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 <module>
    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 <module>
    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:45adminsetgithub: 49468
2012-02-04 02:27:29terry.reedysetstatus: open -> closed

superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator
versions: + Python 3.2, Python 3.3, - Python 3.1
nosy: + terry.reedy

messages: + msg152581
resolution: duplicate
2012-01-12 04:52:43martin.pantersetnosy: + martin.panter
messages: + msg151111
2010-12-15 20:41:39pitrousetassignee: pitrou ->
nosy: georg.brandl, pitrou, gpolo
2010-10-21 13:47:47georg.brandlsetassignee: pitrou

messages: + msg119296
nosy: + georg.brandl
2009-02-13 17:50:47gpolosetfiles: - check_tpiter_before_overriding_msg.diff
2009-02-11 21:34:32gpolosetfiles: + check_before_overriding.diff
messages: + msg81675
2009-02-11 19:41:44pitrousetnosy: + pitrou
messages: + msg81659
2009-02-11 19:35:28gpolosetmessages: + msg81658
2009-02-11 19:34:18gpolosettype: behavior
components: + Interpreter Core
versions: + Python 3.1, Python 2.7
2009-02-11 19:32:42gpolocreate