From: Anthony Sottile Date: Mon, 29 Aug 2022 14:05:24 +0000 (-0400) Subject: ast.parse: check `feature_version` common case first (GH-94640) X-Git-Tag: v3.12.0a1~534 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c2b9348e21a4ba3e995345501898c383972752d;p=thirdparty%2FPython%2Fcpython.git ast.parse: check `feature_version` common case first (GH-94640) --- diff --git a/Lib/ast.py b/Lib/ast.py index ebf4529f79b0..8af6d1ed14db 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -40,13 +40,13 @@ def parse(source, filename='', 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)