diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-08-21 16:31:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 16:31:30 (GMT) |
commit | 10a91d7e98d847b05292eab828ff9ae51308d3ee (patch) | |
tree | a81f95a971c03710f13217cf89e0f12532341af8 /Doc | |
parent | 47022a079eb9d2a2af781abae3de4a71f80247c2 (diff) | |
download | cpython-10a91d7e98d847b05292eab828ff9ae51308d3ee.zip cpython-10a91d7e98d847b05292eab828ff9ae51308d3ee.tar.gz cpython-10a91d7e98d847b05292eab828ff9ae51308d3ee.tar.bz2 |
gh-108113: Make it possible to create an optimized AST (#108154)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/ast.rst | 7 | ||||
-rw-r--r-- | Doc/whatsnew/3.13.rst | 14 |
2 files changed, 19 insertions, 2 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index cd657ae..2237a07 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -2122,10 +2122,12 @@ Async and await Apart from the node classes, the :mod:`ast` module defines these utility functions and classes for traversing abstract syntax trees: -.. function:: parse(source, filename='<unknown>', mode='exec', *, type_comments=False, feature_version=None) +.. function:: parse(source, filename='<unknown>', mode='exec', *, type_comments=False, feature_version=None, optimize=-1) Parse the source into an AST node. Equivalent to ``compile(source, - filename, mode, ast.PyCF_ONLY_AST)``. + filename, mode, flags=FLAGS_VALUE, optimize=optimize)``, + where ``FLAGS_VALUE`` is ``ast.PyCF_ONLY_AST`` if ``optimize <= 0`` + and ``ast.PyCF_OPTIMIZED_AST`` otherwise. If ``type_comments=True`` is given, the parser is modified to check and return type comments as specified by :pep:`484` and :pep:`526`. @@ -2171,6 +2173,7 @@ and classes for traversing abstract syntax trees: .. versionchanged:: 3.13 The minimum supported version for feature_version is now (3,7) + The ``optimize`` argument was added. .. function:: unparse(ast_obj) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 47b868b..bfab868 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -85,6 +85,12 @@ Other Language Changes This change will affect tools using docstrings, like :mod:`doctest`. (Contributed by Inada Naoki in :gh:`81283`.) +* The :func:`compile` built-in can now accept a new flag, + ``ast.PyCF_OPTIMIZED_AST``, which is similar to ``ast.PyCF_ONLY_AST`` + except that the returned ``AST`` is optimized according to the value + of the ``optimize`` argument. + (Contributed by Irit Katriel in :gh:`108113`). + New Modules =========== @@ -94,6 +100,14 @@ New Modules Improved Modules ================ +ast +--- + +* :func:`ast.parse` now accepts an optional argument ``optimize`` + which is passed on to the :func:`compile` built-in. This makes it + possible to obtain an optimized ``AST``. + (Contributed by Irit Katriel in :gh:`108113`). + array ----- |