summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-06-12 00:55:28 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-06-12 00:55:28 (GMT)
commit3ba21070c6ecab83c23cea41a92b42fa651c7ea2 (patch)
tree6fd8a5f50a4c60c100e3a78614d80f830f7a3a73 /Lib/ast.py
parent36eea7af48ca0a1c96b78c82bf95bbd29d2332da (diff)
downloadcpython-3ba21070c6ecab83c23cea41a92b42fa651c7ea2.zip
cpython-3ba21070c6ecab83c23cea41a92b42fa651c7ea2.tar.gz
cpython-3ba21070c6ecab83c23cea41a92b42fa651c7ea2.tar.bz2
bpo-35766: Change format for feature_version to (major, minor) (GH-13992) (GH-13993)
(A single int is still allowed, but undocumented.) https://bugs.python.org/issue35766 (cherry picked from commit 10b55c1643b512b3a2cae8ab89c53683a13ca43e) Co-authored-by: Guido van Rossum <guido@python.org>
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 64e7a25..70fbbdd 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -28,7 +28,7 @@ from _ast import *
def parse(source, filename='<unknown>', mode='exec', *,
- type_comments=False, feature_version=-1):
+ type_comments=False, feature_version=None):
"""
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
@@ -37,6 +37,13 @@ def parse(source, filename='<unknown>', mode='exec', *,
flags = PyCF_ONLY_AST
if type_comments:
flags |= PyCF_TYPE_COMMENTS
+ if isinstance(feature_version, tuple):
+ major, minor = feature_version # Should be a 2-tuple.
+ assert major == 3
+ 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)