Skip to content

Incorrect behavior of inspect.signature(f).bind #87106

Description

@slavkostrov
BPO 42940

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 = None
created_at = <Date 2021-01-16.16:30:52.922>
labels = ['type-bug', '3.8', '3.9']
title = 'Incorrect behavior of inspect.signature(f).bind'
updated_at = <Date 2021-01-16.16:30:52.922>
user = 'https://bugs.python.org/slavkostrov'

bugs.python.org fields:

activity = <Date 2021-01-16.16:30:52.922>
actor = 'slavkostrov'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2021-01-16.16:30:52.922>
creator = 'slavkostrov'
dependencies = []
files = []
hgrepos = []
issue_num = 42940
keywords = []
message_count = 1.0
messages = ['385143']
nosy_count = 1.0
nosy_names = ['slavkostrov']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42940'
versions = ['Python 3.8', 'Python 3.9']

Linked PRs

Activity

  1. slavkostrov commented on Jan 16, 2021

    slavkostrovmannequin
    MannequinAuthor
    >>> def foo(a, /, b=1, **kwargs): pass
    ...
    >>> foo(a=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: foo() missing 1 required positional argument: 'a'
    
    >>> inspect.signature(foo).bind(a=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "\Python\Python39\lib\inspect.py", line 3062, in bind
        return self._bind(args, kwargs)
      File "\Python\Python39\lib\inspect.py", line 2958, in _bind
        raise TypeError(msg) from None
    TypeError: 'a' parameter is positional only, but was passed as a keyword

    There is a different behaviour between a simple function call and inspect.signature(foo).bind - different TypeError messages.

    I think inspect should check for VARKEYWORDS before throwing an error and throw only if there are not.

  2. transferred this issue fromon Apr 10, 2022
  3. jacobtylerwalls commented on Apr 10, 2023

    @jacobtylerwalls
    Contributor

    In another case, inspect.signature(foo).bind gives a TypeError when no TypeError is even raised in the actual call:

    >>> def foo(a=0, /, b=1, **kwargs): pass
    ...
    >>> foo(a=1)
    >>> inspect.signature(foo).bind(a=1)
    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 3037, in bind
        return self._bind(args, kwargs)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 2933, in _bind
        raise TypeError(msg) from None
    TypeError: 'a' parameter is positional only, but was passed as a keyword
  4. added a commit that references this issue on Apr 10, 2023
  5. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 23, 2023
  6. added a commit that references this issue on May 13, 2024
  7. added 2 commits that reference this issue on May 13, 2024
  8. added 2 commits that reference this issue on May 13, 2024
  9. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions