Repository navigation
Incorrect behavior of inspect.signature(f).bind #87106
Copy link
Copy link
Closed
Labels
3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
slavkostrov commented
on Jan 16, 2021 slavkostrovmannequinMannequinAuthorMore actions>>> 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.
- added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jan 16, 2021 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
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 23, 2023 - added a commit that references this issue
on May 13, 2024 - added a commit that references this issue
on Jul 17, 2024
Metadata
Metadata
Assignees
Labels
3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
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:
bugs.python.org fields:
Linked PRs
inspect.signature.bindhandling of positional-only arguments with**kwargs#103404