Open sobolevn opened 1 year ago
The important thing is having modern fully capable alternatives in place that can satisfy the needs of users of the existing APIs. Without that, deprecating these only causes pain as no functional alternatives exist. So overall, agreed: Succeed in doing
#1
(modern alternatives) and#2
(open ended deprecation) can actually be started.
I think that we should do it on a per-function basis. So, we can work incrementally on it.
It is also worth considering if the replacement can be done such that it is usable Python 3.8-3.12 as a PyPI package so that existing users of the APIs could go ahead and move off everywhere.
Good idea!
I propose to provide modern alternatives to and deprecate these inspect members
Why not just using inspect.singature()? Would you mind to elaborate what are signature() issues? Its design allowed to support smoothly positional only arguments.
Why not just using inspect.singature()?
I am using inspect.Signature.from_code
:)
But, right now it was impossible to use Signature
created from CodeType
.
My PR solves that, so there's now no need to use getargs()
at all.
For each of these (https://github.com/python/cpython/pull/112236, https://github.com/python/cpython/pull/112279, https://github.com/python/cpython/pull/112314), please can you add documentation either to Porting to Python 3.13 (and/or their relevant docs pages) that shows examples of code using the old API, and the recommended replacement?
This will help people upgrade.
Sure! I will update all PRs soon.
Some usage stats from the top 8,000 (not 5k) PyPI projects, downloaded 2023-09-01. Some false positives in here, but it gives a good overview of use.
"\binspect\b.*\bgetcallargs\b"
- Found 56 matching lines in 40 projects"\binspect\b.*\bgetargs\b"
- Found 20 matching lines in 12 projects"\binspect\b.*\bgetfullargspec\b"
- Found 5967 matching lines in 365 projectsThat last one looks pretty high.
What's the status of this issue?
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 requiredgetargvalues()
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
methodNotice: 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 asIt has a rich history of deprecation / undeprecation:
More history: https://github.com/python/cpython/issues/76371#issuecomment-1270007408
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()
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