Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print gives wrong error when printing *generator #65158

Closed
jneb mannequin opened this issue Mar 17, 2014 · 3 comments
Closed

print gives wrong error when printing *generator #65158

jneb mannequin opened this issue Mar 17, 2014 · 3 comments
Labels
topic-IO type-bug An unexpected behavior, bug, or error

Comments

@jneb
Copy link
Mannequin

jneb mannequin commented Mar 17, 2014

BPO 20959
Nosy @jneb, @ned-deily, @vadmium
Superseder
  • bpo-4806: Function calls taking a generator as star argument can mask TypeErrors in the generator
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-03-19.05:32:26.469>
    created_at = <Date 2014-03-17.14:17:49.919>
    labels = ['type-bug', 'expert-IO']
    title = 'print gives wrong error when printing *generator'
    updated_at = <Date 2014-03-19.05:32:26.440>
    user = 'https://github.com/jneb'

    bugs.python.org fields:

    activity = <Date 2014-03-19.05:32:26.440>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-03-19.05:32:26.469>
    closer = 'ned.deily'
    components = ['IO']
    creation = <Date 2014-03-17.14:17:49.919>
    creator = 'jneb'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 20959
    keywords = []
    message_count = 3.0
    messages = ['213869', '214053', '214054']
    nosy_count = 3.0
    nosy_names = ['jneb', 'ned.deily', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '4806'
    type = 'behavior'
    url = 'https://bugs.python.org/issue20959'
    versions = ['Python 3.3']

    @jneb
    Copy link
    Mannequin Author

    jneb mannequin commented Mar 17, 2014

    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

    @jneb jneb mannequin added topic-IO type-bug An unexpected behavior, bug, or error labels Mar 17, 2014
    @vadmium
    Copy link
    Member

    vadmium commented Mar 19, 2014

    Yet another duplicate of bpo-4806, by the looks

    @ned-deily
    Copy link
    Member

    Thanks for the report. And thanks for noting the duplicate, Martin.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants