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

inspect.getcallargs() raises the wrong error if 3+ arguments are missing #65016

Closed
jlowin mannequin opened this issue Mar 1, 2014 · 4 comments
Closed

inspect.getcallargs() raises the wrong error if 3+ arguments are missing #65016

jlowin mannequin opened this issue Mar 1, 2014 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jlowin
Copy link
Mannequin

jlowin mannequin commented Mar 1, 2014

BPO 20817
Nosy @ncoghlan, @larryhastings, @1st1
Files
  • issue20817.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 = 'https://github.com/1st1'
    closed_at = <Date 2014-03-27.22:45:42.214>
    created_at = <Date 2014-03-01.16:35:04.836>
    labels = ['type-bug', 'library']
    title = 'inspect.getcallargs() raises the wrong error if 3+ arguments are missing'
    updated_at = <Date 2014-03-27.22:46:06.513>
    user = 'https://bugs.python.org/jlowin'

    bugs.python.org fields:

    activity = <Date 2014-03-27.22:46:06.513>
    actor = 'yselivanov'
    assignee = 'yselivanov'
    closed = True
    closed_date = <Date 2014-03-27.22:45:42.214>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2014-03-01.16:35:04.836>
    creator = 'jlowin'
    dependencies = []
    files = ['34261']
    hgrepos = []
    issue_num = 20817
    keywords = ['patch']
    message_count = 4.0
    messages = ['212514', '212515', '214988', '214989']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'larry', 'python-dev', 'yselivanov', 'jlowin']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20817'
    versions = ['Python 3.3', 'Python 3.4']

    @jlowin
    Copy link
    Mannequin Author

    jlowin mannequin commented Mar 1, 2014

    If inspect.getcallargs() is called on a function and three or more arguments are missing, an IndexError is raised instead of the expected TypeError.

    This bug is present in Python 3.3 and 3.4.0 rc1 (5e05d7d3db9c). However, it worked as expected in Python 2.7.6.

    Example:

    >> import inspect
    >> def fn(a, b, c):
    >> pass
    >> inspect.getcallargs(fn)

    Result:
    IndexError: tuple index out of range
    Expected:
    TypeError: fn() missing 3 required positional arguments: 'a', 'b' and 'c'

    @jlowin jlowin mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 1, 2014
    @jlowin
    Copy link
    Mannequin Author

    jlowin mannequin commented Mar 1, 2014

    The bug is caused by a list of names not getting properly expanded when generating the error message. This patch fixes it (simply by adding a * in the appropriate place) and tests that a TypeError, not an IndexError, is raised.

    @1st1 1st1 self-assigned this Mar 1, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 27, 2014

    New changeset 35302cc4fc93 by Yury Selivanov in branch 'default':
    inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.
    http://hg.python.org/cpython/rev/35302cc4fc93

    New changeset 9f06cbb7962b by Yury Selivanov in branch '3.4':
    inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.
    http://hg.python.org/cpython/rev/9f06cbb7962b

    @python-dev python-dev mannequin closed this as completed Mar 27, 2014
    @1st1
    Copy link
    Member

    1st1 commented Mar 27, 2014

    Fixed for 3.4.1 and 3.5.
    Thanks for the contribution!

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant