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
ast.Constant.n is documented to be deprecated, but you don't get any warning when you use it:
$ python3.11 -Wd
Python 3.11.0a5 (main, Feb 12 2022, 17:11:59) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> help(ast.Constant.n)
Help on property:
It is because we did not have a plan for removing deprecates features. Deprecation in documentation only helps third-party code. Instead of adding a complex code which switches between using old and new names depending on Python version, the third-party code can continue to use old names without worring about deprecation warnings, and switch completely to using new features only when support of old Python versions be dropped. 3.7 and 3.8 are not so old and may be still supported in third-party code.
I have created a PR which adds deprecation warnings, but I am not sure that it is worth to include it in 3.11.
Python 3.12.1 (v3.12.1:2305ca5144, Dec 7 2023, 17:23:38) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> help(ast.Constant.n)
Help on property:
Deprecated. Use value instead.
>>> ast.Constant(value=42).n
<stdin>:1: DeprecationWarning: Attribute n is deprecated and will be removed in Python 3.14; use value instead
42
Activity
jwilk commentedon Feb 19, 2022
ast.Constant.n is documented to be deprecated, but you don't get any warning when you use it:
serhiy-storchaka commentedon Feb 19, 2022
It is because we did not have a plan for removing deprecates features. Deprecation in documentation only helps third-party code. Instead of adding a complex code which switches between using old and new names depending on Python version, the third-party code can continue to use old names without worring about deprecation warnings, and switch completely to using new features only when support of old Python versions be dropped. 3.7 and 3.8 are not so old and may be still supported in third-party code.
I have created a PR which adds deprecation warnings, but I am not sure that it is worth to include it in 3.11.
gh-90953: Emit deprecation warnings for `ast` features deprecated in …
pythongh-90953: Emit deprecation warnings for `ast` features deprecat…
pythongh-90953: Don't use deprecated AST nodes in clinic.py
gh-90953: Don't use deprecated AST nodes in clinic.py (#104322)
Merge branch 'main' into fixloadsuperspec
hugovk commentedon Jan 11, 2024
A deprecation warning is now raised:
Replace `ast.Num` with `ast.Constant`
pythongh-90953: Don't use deprecated AST nodes in clinic.py (pythonGH…
pythongh-90953: Don't use deprecated AST nodes in clinic.py (pythonGH…
pythongh-90953: Don't use deprecated AST nodes in clinic.py (pythonGH…
[3.10] gh-90953: Don't use deprecated AST nodes in clinic.py (GH-104322…
[3.9] gh-90953: Don't use deprecated AST nodes in clinic.py (GH-104322)…
[3.11] gh-90953: Don't use deprecated AST nodes in clinic.py (GH-104322…