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

The ValueError raised by failing to unpack sequence should have more information. #47321

Closed
jml mannequin opened this issue Jun 10, 2008 · 7 comments
Closed

The ValueError raised by failing to unpack sequence should have more information. #47321

jml mannequin opened this issue Jun 10, 2008 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@jml
Copy link
Mannequin

jml mannequin commented Jun 10, 2008

BPO 3071
Nosy @birkenfeld, @jackdied, @devdanzin, @benjaminp
Files
  • how-many-values.patch
  • 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 2009-07-27.00:12:35.240>
    created_at = <Date 2008-06-10.02:06:05.524>
    labels = ['interpreter-core', 'type-feature']
    title = 'The ValueError raised by failing to unpack sequence should have more information.'
    updated_at = <Date 2010-07-10.22:01:30.471>
    user = 'https://bugs.python.org/jml'

    bugs.python.org fields:

    activity = <Date 2010-07-10.22:01:30.471>
    actor = 'eric.araujo'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-07-27.00:12:35.240>
    closer = 'jackdied'
    components = ['Interpreter Core']
    creation = <Date 2008-06-10.02:06:05.524>
    creator = 'jml'
    dependencies = []
    files = ['14574']
    hgrepos = []
    issue_num = 3071
    keywords = ['patch']
    message_count = 7.0
    messages = ['67885', '67889', '87920', '90968', '90972', '90974', '109843']
    nosy_count = 6.0
    nosy_names = ['georg.brandl', 'exarkun', 'jackdied', 'ajaksu2', 'benjamin.peterson', 'jml']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3071'
    versions = ['Python 2.7', 'Python 3.2']

    @jml
    Copy link
    Mannequin Author

    jml mannequin commented Jun 10, 2008

    Here's the current message:

    Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) 
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> [foo] = [2, 3]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: too many values to unpack

    It would be good if the message of the ValueError contained information
    about how many values were expected and how many values were given.

    @jml jml mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jun 10, 2008
    @benjaminp
    Copy link
    Contributor

    Would you like to submit a patch?

    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented May 16, 2009

    What would happen with infinite iterables?

    import itertools 
    [foo] = itertools.count()

    @jackdied
    Copy link
    Contributor

    The code that raises the error is in ceval.c which is a critical path.
    The raise is done as soon the iterator has one more item than is needed
    (see Daniel Diniz's comments on infinite iterators). While the check
    could return more useful information for known non-infinite iterators
    (tuples, lists, etc) it would have to do a big if/else for all the core
    types (but excluding their subclasses!). If someone wants to submit
    that patch and a benchmark that shows no slowdown I'll reopen the bug.

    Until then I'm closing as WONTFIX.

    @exarkun
    Copy link
    Mannequin

    exarkun mannequin commented Jul 27, 2009

    Here's a patch implementing part of the requested feature.

    pystones cannot tell the difference between trunk@HEAD with or without
    this patch applied. Both report a maximum of 78125 pystones/second/

    @jackdied
    Copy link
    Contributor

    I was looking at 3.x, JP's patch is relative to 2.x and takes a little
    more unpacking (a couple function calls more) but looks to me to be the
    same. In 2.x unpack_iterable() sets/returns an error once one item more
    than is required is received. It doesn't give any more information
    about known-length builtins than anything else. The same error is
    raised for million-item lists as three item lists if the expected number
    to unpack is two.

    The original feature request was that the error message be better if,
    say the left hand side wanted three arguments and the right hand side
    provided four. The ceval.c code is different between 2.x and 3.x but
    they both only check for 'exactly the right number, or one or more too
    many.'

    @birkenfeld
    Copy link
    Member

    Applied patch in r82759.

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants