Skip to content

Commit 85a2eef

Browse files
bpo-32892: Update the documentation for handling constants in AST. (pythonGH-18514)
1 parent c33bdbb commit 85a2eef

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Doc/library/ast.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ Node classes
101101
node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),
102102
lineno=0, col_offset=0)
103103

104+
.. versionchanged:: 3.8
105+
106+
Class :class:`ast.Constant` is now used for all constants.
107+
104108
.. deprecated:: 3.8
105109

106-
Class :class:`ast.Constant` is now used for all constants. Old classes
107-
:class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`,
110+
Old classes :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`,
108111
:class:`ast.NameConstant` and :class:`ast.Ellipsis` are still available,
109-
but they will be removed in future Python releases.
112+
but they will be removed in future Python releases. In the meanwhile,
113+
instantiating them will return an instance of a different class.
110114

111115

112116
.. _abstract-grammar:

Doc/whatsnew/3.8.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,12 @@ Changes in the Python API
19401940
:exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`.
19411941
(Contributed by Xiang Zhang in :issue:`33106`.)
19421942

1943+
* Simplified AST for literals. All constants will be represented as
1944+
:class:`ast.Constant` instances. Instantiating old classes ``Num``,
1945+
``Str``, ``Bytes``, ``NameConstant`` and ``Ellipsis`` will return
1946+
an instance of ``Constant``.
1947+
(Contributed by Serhiy Storchaka in :issue:`32892`.)
1948+
19431949
* :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE`
19441950
environment variable and does not use :envvar:`HOME`, which is not normally
19451951
set for regular user accounts.

0 commit comments

Comments
 (0)