Skip to content

Commit 988aeba

Browse files
bpo-32892: Update the documentation for handling constants in AST. (GH-18514)
(cherry picked from commit 85a2eef) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent ea316fd commit 988aeba

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Doc/library/ast.rst

Lines changed: 7 additions & 3 deletions
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,12 @@ Changes in the Python API
19421942
:exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`.
19431943
(Contributed by Xiang Zhang in :issue:`33106`.)
19441944

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

0 commit comments

Comments
 (0)