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.signature.bind does not correctly handle keyword argument with same name as positional-only parameter #82659

Closed
orez mannequin opened this issue Oct 15, 2019 · 4 comments
Assignees
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@orez
Copy link
Mannequin

orez mannequin commented Oct 15, 2019

BPO 38478
Nosy @pablogsal, @miss-islington, @orez-
PRs
  • bpo-38478: Correctly handle keyword argument with same name as positional-only parameter #16800
  • [3.8] bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800) #16801
  • 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/pablogsal'
    closed_at = <Date 2019-10-15.12:46:36.956>
    created_at = <Date 2019-10-15.02:26:32.669>
    labels = ['3.8', 'type-bug', 'library', '3.9']
    title = 'inspect.signature.bind does not correctly handle keyword argument with same name as positional-only parameter'
    updated_at = <Date 2019-10-15.12:46:36.955>
    user = 'https://github.com/orez'

    bugs.python.org fields:

    activity = <Date 2019-10-15.12:46:36.955>
    actor = 'pablogsal'
    assignee = 'pablogsal'
    closed = True
    closed_date = <Date 2019-10-15.12:46:36.956>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2019-10-15.02:26:32.669>
    creator = 'brian.shaginaw'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38478
    keywords = ['patch']
    message_count = 4.0
    messages = ['354683', '354710', '354714', '354718']
    nosy_count = 3.0
    nosy_names = ['pablogsal', 'miss-islington', 'brian.shaginaw']
    pr_nums = ['16800', '16801']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue38478'
    versions = ['Python 3.8', 'Python 3.9']

    @orez
    Copy link
    Mannequin Author

    orez mannequin commented Oct 15, 2019

    >>> import inspect
    >>> def foo(bar, /, **kwargs):
    ...   print(bar, kwargs)
    ...
    >>> foo(1, bar=2)
    1 {'bar': 2}
    >>> inspect.signature(foo).bind(1, bar=2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 3025, in bind
        return self._bind(args, kwargs)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 2964, in _bind
        raise TypeError(
    TypeError: multiple values for argument 'bar'

    Python 3.8 introduced positional-only parameters, which allow parameter names to remain available for use in **kwargs. It looks like inspect.signature.bind does not recognize this, and thinks the parameter is being passed twice, which causes the above TypeError.

    Expected result: <BoundArguments (bar=1, kwargs={'bar': 2})>

    @orez orez mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 15, 2019
    @pablogsal pablogsal self-assigned this Oct 15, 2019
    @pablogsal
    Copy link
    Member

    Thanks, Brian for the report!

    I have a fix ready. When merged, this will be available in the next release.

    @pablogsal pablogsal added the 3.9 only security fixes label Oct 15, 2019
    @pablogsal
    Copy link
    Member

    New changeset f3ef06a by Pablo Galindo in branch 'master':
    bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800)
    f3ef06a

    @miss-islington
    Copy link
    Contributor

    New changeset f705f8e by Miss Islington (bot) in branch '3.8':
    bpo-38478: Correctly handle keyword argument with same name as positional-only parameter (GH-16800)
    f705f8e

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

    No branches or pull requests

    2 participants