You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note 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:
Feature or enhancement
Proposal:
I propose to provide modern alternatives to and deprecate these
inspectmembers: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 requiredgetargvalues()only works withframeobjects, but it does not work correctly with pos-only and kw-only parameters. Bug:inspect.getargvaluesdoes 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_framemethodNotice: 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.getcallargsdoes not raiseTypeErrorfor pos-only passed as keywords · Issue #107831 · python/cpython · GitHub). Can it be replaced with modern tooling? Yes:inspect.Signature.bindgetfullargspec()is documented asIt has a rich history of deprecation / undeprecation:
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.signaturehas some differences. But,getfullargspec()usessignature()internallyHas 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
Signature.from_codemethod #108902inspect.getcallargsand slate it for removal #112236inspect.getargs, slate it for removal in 3.15 #112279inspect.getfullargspecand slate it for removal in 3.15 #112314inspect.getargvaluesandinspect.formatargvalues, provide modern alternative #112639inspect.Signature.from_frame#116537bound_argtoSignature.from_callable()andsignature()#116559