Message78788
| Author |
hagen |
| Recipients |
hagen |
| Date |
2009年01月02日.12:46:01 |
| SpamBayes Score |
2.8092462e-10 |
| Marked as misclassified |
No |
| Message-id |
<1230900364.95.0.0532833034138.issue4806@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2009年01月02日 12:46:05 | hagen | set | recipients:
+ hagen |
| 2009年01月02日 12:46:04 | hagen | set | messageid: <1230900364.95.0.0532833034138.issue4806@psf.upfronthosting.co.za> |
| 2009年01月02日 12:46:02 | hagen | link | issue4806 messages |
| 2009年01月02日 12:46:01 | hagen | create |
|