summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2022-08-29 14:05:24 (GMT)
committerGitHub <noreply@github.com>2022-08-29 14:05:24 (GMT)
commit9c2b9348e21a4ba3e995345501898c383972752d (patch)
treec34e379990ab41eec808c6fe7c5f9ab53f2d4484 /Lib
parent026ab6f4e50658b798be8d1ccf4f3005966e33ea (diff)
downloadcpython-9c2b9348e21a4ba3e995345501898c383972752d.zip
cpython-9c2b9348e21a4ba3e995345501898c383972752d.tar.gz
cpython-9c2b9348e21a4ba3e995345501898c383972752d.tar.bz2
ast.parse: check `feature_version` common case first (GH-94640)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ast.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index ebf4529..8af6d1e 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -40,13 +40,13 @@ def parse(source, filename='<unknown>', mode='exec', *,
flags = PyCF_ONLY_AST
if type_comments:
flags |= PyCF_TYPE_COMMENTS
- if isinstance(feature_version, tuple):
+ if feature_version is None:
+ feature_version = -1
+ elif isinstance(feature_version, tuple):
major, minor = feature_version # Should be a 2-tuple.
if major != 3:
raise ValueError(f"Unsupported major version: {major}")
feature_version = minor
- elif feature_version is None:
- feature_version = -1
# Else it should be an int giving the minor version for 3.x.
return compile(source, filename, mode, flags,
_feature_version=feature_version)