We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeError
Consider this example:
>>> def a(p, /, a, b=2, *, f): ... ... >>> import inspect >>> inspect.getcallargs(a, p=1, a=2, b=3, f=4) {'p': 1, 'a': 2, 'b': 3, 'f': 4}
Compare it with the runtime:
>>> def a(p, /, a, b=2, *, f): ... ... >>> a(p=1, a=2, b=3, f=4) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: a() got some positional-only arguments passed as keyword arguments: 'p'
And with inspect.signature.bind:
inspect.signature.bind
>>> inspect.signature(a).bind(p=1, a=2, b=3, f=4) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 3294, in bind return self._bind(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 3186, in _bind raise TypeError(msg) from None TypeError: 'p' parameter is positional only, but was passed as a keyword
The issue itself is not easy to fix, because inside getcallargs uses getfullargspec, which does not differentiate pos-only from pos-or-keyword:
getcallargs
getfullargspec
cpython/Lib/inspect.py
Lines 1582 to 1583 in 39ef93e
So, we cannot know that p is pos-only.
p
Note that inspect.getcallargs is deprecated in the docs. So, I propose deprecating getcallargs with a DeprecationWarning in 3.13.
DeprecationWarning
3.13
The text was updated successfully, but these errors were encountered:
See https://discuss.python.org/t/consider-deprecating-a-bunch-of-inspect-functions/31369
Sorry, something went wrong.
inspect
No branches or pull requests
Consider this example:
Compare it with the runtime:
And with
inspect.signature.bind
:The issue itself is not easy to fix, because inside
getcallargs
usesgetfullargspec
, which does not differentiate pos-only from pos-or-keyword:cpython/Lib/inspect.py
Lines 1582 to 1583 in 39ef93e
So, we cannot know that
p
is pos-only.Note that
inspect.getcallargs
is deprecated in the docs.So, I propose deprecating
getcallargs
with aDeprecationWarning
in3.13
.The text was updated successfully, but these errors were encountered: