Skip to content

inspect.signature.bind does not correctly handle keyword argument with same name as positional-only parameter #82659

Description

@orez
mannequin
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']

    Activity

    1. orez commented on Oct 15, 2019

      orezmannequin
      MannequinAuthor
      >>> 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})>

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Oct 15, 2019
    3. self-assigned this
      on Oct 15, 2019
    4. pablogsal commented on Oct 15, 2019

      @pablogsal
      Member

      Thanks, Brian for the report!

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

    5. pablogsal commented on Oct 15, 2019

      @pablogsal
      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

    6. miss-islington commented on Oct 15, 2019

      @miss-islington
      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

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions