Description
Feature or enhancement
Proposal:
I propose to provide modern alternatives to and deprecate these inspect
members:
-
getargs()
undocumented helper used in getargvalues. It works with__code__
objects. Can it be replaced with modern tooling? Not yet: we have an internal helper to get signatures from__code__
objects: https://github.com/python/cpython/blob/39ef93edb9802dccdb6555d4209ac2e60875a011/Lib/inspect.py#L2423-L2488 But, some refactoring is required -
getargvalues()
only works withframe
objects, but it does not work correctly with pos-only and kw-only parameters. Bug:inspect.getargvalues
does not work correctly for pos-only and kw-only arguments · Issue #107833 · python/cpython · GitHub Can it be replaced with modern tooling? No, I propose addinginspect.Signature.from_frame
method
Notice: formatargvalues should also be deprecated, because the only way to use is together with getargvalues.
There was a reverted attempt to depracate them in 3.5
-
getcallargs()
was documented as deprecated for a long time, it also has known bugs with pos-only params (inspect.getcallargs
does not raiseTypeError
for pos-only passed as keywords · Issue #107831 · python/cpython · GitHub). Can it be replaced with modern tooling? Yes:inspect.Signature.bind
-
getfullargspec()
is documented asNote that signature() and Signature Object provide the recommended API for callable introspection, and support additional behaviours (like positional-only arguments) that are sometimes encountered in extension module APIs. This function is retained primarily for use in code that needs to maintain compatibility with the Python 2 inspect module API.
It has a rich history of deprecation / undeprecation:
- Deprecated: inspect: Deprecate getfullargspec? #64637
- Undeprecated: Undeprecate inspect.getfullargspec() #71359
- Suggested to be deprecated again: Deprecate legacy introspection APIs in the inspect module #76371
More history: #76371 (comment)
It is broken in a sense that it does not differentiate pos-only from pos-or-keyword parameters.
Can it be replaced with modern tooling? Partially: inspect.signature
has some differences. But, getfullargspec()
uses signature()
internally
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/consider-deprecating-a-bunch-of-inspect-functions/31369
CC @gpshead
Linked PRs
- gh-108901: Add
Signature.from_code
method #108902 - gh-108901: Deprecate
inspect.getcallargs
and slate it for removal #112236 - gh-108901: Deprecate
inspect.getargs
, slate it for removal in 3.15 #112279 - gh-108901: Deprecate
inspect.getfullargspec
and slate it for removal in 3.15 #112314 - gh-108901: Deprecate
inspect.getargvalues
andinspect.formatargvalues
, provide modern alternative #112639 - gh-108901: Add
inspect.Signature.from_frame
#116537 - gh-108901: Add
bound_arg
toSignature.from_callable()
andsignature()
#116559