[New-bugs-announce] [issue4806] Function calls taking a generator as star argument can mask TypeErrors in the generator

Hagen Fürstenau report at bugs.python.org
Fri Jan 2 13:46:04 CET 2009


New submission from Hagen Fürstenau <hfuerstenau at gmx.net>:

If we call some function f with a generator as star argument and this
generator raises a TypeError, we get the following exception:

>>> def f(x): pass
... 
>>> def broken(): raise TypeError
... 
>>> f(*(broken() for x in (0,)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() argument after * must be a sequence, not generator

This is a misleading error message, as it's usually no problem to use a
generator as a star argument. Even just replacing the TypeError by some
other exception leads to the expected result, i.e. the exception gets
correctly propagated.

The problem seems to be around line 3710 of Python/ceval.c where the
generator is converted to a tuple. If this conversion raises a
TypeError, then the error message is replaced, which will mask any
TypeError raised by the generator.

I'm not sure how to solve this. We probably can't distinguish a "good"
TypeError from a "bad" TypeError at this point, so we might have to make
a special case for the conversion of generators.

----------
components: Interpreter Core
messages: 78788
nosy: hagen
severity: normal
status: open
title: Function calls taking a generator as star argument can mask TypeErrors in the generator
type: behavior
versions: Python 2.6, Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4806>
_______________________________________


More information about the New-bugs-announce mailing list