-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-108901: Deprecate inspect.getargvalues and inspect.formatargvalues, provide modern alternative
#112639
New issue
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
base: main
Are you sure you want to change the base?
Conversation
|
Any progress? |
|
@hugovk I've implemented your suggestion about porting to Python 3.13, please take a look. |
vstinner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please start with a separated PR which adds Signature.from_frame(). Once it will be merge, you can simplify this PR to only deprecate methods.
| for name in arg_names[:pos_count]: | ||
| if frame.f_locals and name in frame.f_locals: | ||
| defaults.append(frame.f_locals[name]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you can move if frame.f_locals: out of this loop and the one below.
|
(Copying and pasting my reply from elsewhere :) PEP 387 says two releases of deprecation is the minimum but also:
Does that apply here? If so, and if the replacement is added in 3.13, then the removals should be when 3.13 is EOL in October 2029, meaning removal in 3.18, not 3.15. |
| class TestSignatureFromFrame(unittest.TestCase): | ||
| def test_signature_from_frame(self): | ||
| def inner(a=1, /, b=2, *e, c: int = 3, d, **f) -> None: | ||
| global fr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a global sounds like a bad idea. You can use a "nonlocal" instead.
Sometimes, I use a mutable type instead, which is more or less the same:
ns = {}
def func():
ns['name'] = value
Now
getargvaluesis deprecated (together withformatargvalues). People should useSignatureobject instead.inspect313backports newSignature.from_frameto 3.8-3.12: https://github.com/wemake-services/inspect313/blob/a310c03c440156062504b14a6325fbbe84687052/inspect313/__init__.py#L25-L48 and https://github.com/wemake-services/inspect313/blob/master/README.md#replace-inspectgetargvalues-with-inspectsignaturefrom_frameinspectmodule, deprecate old incorrect APIs #108901📚 Documentation preview 📚: https://cpython-previews--112639.org.readthedocs.build/