From 405447803685ac1c0b66481a45a898616d41e8c5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 15 Feb 2020 14:32:18 +0200 Subject: [PATCH 1/2] bpo-32892: Update the documentation for handling constants in AST. --- Doc/library/ast.rst | 10 +++++++--- Doc/whatsnew/3.8.rst | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 2cee8738e5834c..fead52f0a7d152 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -101,12 +101,16 @@ Node classes node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0), lineno=0, col_offset=0) +.. versionchanged:: 3.8 + + Class :class:`ast.Constant` is now used for all constants. + .. deprecated:: 3.8 - Class :class:`ast.Constant` is now used for all constants. Old classes - :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`, + Old classes :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`, :class:`ast.NameConstant` and :class:`ast.Ellipsis` are still available, - but they will be removed in future Python releases. + but they will be removed in future Python releases. In meanwhile, + instantiating them will return an instance of different class. .. _abstract-grammar: diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index cb4c518662d6ba..09047c460df01c 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1940,6 +1940,12 @@ Changes in the Python API :exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`. (Contributed by Xiang Zhang in :issue:`33106`.) +* Simplified AST for literals. All constants will be represented as + :class:`ast.Constant` instances. Instantiating old classes ``Num``, + ``Str``, ``Bytes``, ``NameConstant`` and ``Ellipsis`` will return + an instance of ``Constant``. + (Contributed by Serhiy Storchaka in :issue:`32892`.) + * :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE` environment variable and does not use :envvar:`HOME`, which is not normally set for regular user accounts. From c01e0d3d69896c67a1c184c48fc66b9f1eb33268 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 16 Feb 2020 18:51:58 +0200 Subject: [PATCH 2/2] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> --- Doc/library/ast.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index fead52f0a7d152..bfd571deb4fd1f 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -109,8 +109,8 @@ Node classes Old classes :class:`ast.Num`, :class:`ast.Str`, :class:`ast.Bytes`, :class:`ast.NameConstant` and :class:`ast.Ellipsis` are still available, - but they will be removed in future Python releases. In meanwhile, - instantiating them will return an instance of different class. + but they will be removed in future Python releases. In the meanwhile, + instantiating them will return an instance of a different class. .. _abstract-grammar: