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: print gives wrong error when printing *generator
Type: behavior Stage: resolved
Components: IO Versions: Python 3.3
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: jneb, martin.panter, ned.deily
Priority: normal Keywords:

Created on 2014-03-17 14:17 by jneb, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg213869 - (view) Author: Jurjen N.E. Bos (jneb) * Date: 2014-03-17 14:17
One of the more interesting ways to use print is printing output of a generator, as print(*generator()).
But if the generator generates a typeError, you get a very unhelpful error message:
>>> #the way it works OK
>>> def f(): yield 'a'+'b'
...
>>> print(*f())
ab
>>> #Now with a type error
>>> def f(): yield 'a'+5
...
>>> print(*f())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: print() argument after * must be a sequence, not generator

The problem is twofold:
- the message is plainly wrong, since it does work with a generator
- the actual error is hidden from view
msg214053 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2014-03-19 05:04
Yet another duplicate of Issue 4806, by the looks
msg214054 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-03-19 05:32
Thanks for the report.  And thanks for noting the duplicate, Martin.
History
Date User Action Args
2022-04-11 14:58:00adminsetgithub: 65158
2014-03-19 05:32:26ned.deilysetstatus: open -> closed

superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator

nosy: + ned.deily
messages: + msg214054
resolution: duplicate
stage: resolved
2014-03-19 05:04:11martin.pantersetnosy: + martin.panter
messages: + msg214053
2014-03-17 14:17:49jnebcreate