aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-08-21 17:31:30 +0100
committerGitHub <noreply@github.com>2023-08-21 16:31:30 +0000
commit10a91d7e98d847b05292eab828ff9ae51308d3ee (patch)
treea81f95a971c03710f13217cf89e0f12532341af8 /Lib/ast.py
parent47022a079eb9d2a2af781abae3de4a71f80247c2 (diff)
downloadcpython-10a91d7e98d847b05292eab828ff9ae51308d3ee.tar.gz
cpython-10a91d7e98d847b05292eab828ff9ae51308d3ee.zip
gh-108113: Make it possible to create an optimized AST (#108154)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index a307f3ecd06..45b95963f81 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -32,13 +32,15 @@ from enum import IntEnum, auto, _simple_enum
def parse(source, filename='<unknown>', mode='exec', *,
- type_comments=False, feature_version=None):
+ type_comments=False, feature_version=None, optimize=-1):
"""
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
Pass type_comments=True to get back type comments where the syntax allows.
"""
flags = PyCF_ONLY_AST
+ if optimize > 0:
+ flags |= PyCF_OPTIMIZED_AST
if type_comments:
flags |= PyCF_TYPE_COMMENTS
if feature_version is None:
@@ -50,7 +52,7 @@ def parse(source, filename='<unknown>', mode='exec', *,
feature_version = minor
# Else it should be an int giving the minor version for 3.x.
return compile(source, filename, mode, flags,
- _feature_version=feature_version)
+ _feature_version=feature_version, optimize=optimize)
def literal_eval(node_or_string):