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 10b55c1643)

Co-authored-by: Guido van Rossum <guido@python.org>
This commit is contained in:
Miss Islington (bot) 2019-06-11 17:55:28 -07:00 committed by Victor Stinner
parent 36eea7af48
commit 3ba21070c6
4 changed files with 19 additions and 10 deletions

View file

@ -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)