flags |= PyCF_TYPE_COMMENTS
if isinstance(feature_version, tuple):
major, minor = feature_version # Should be a 2-tuple.
- assert major == 3
+ if major != 3:
+ raise ValueError(f"Unsupported major version: {major}")
feature_version = minor
elif feature_version is None:
feature_version = -1
with self.assertRaises(SyntaxError):
ast.parse('(x := 0)', feature_version=(3, 7))
+ def test_invalid_major_feature_version(self):
+ with self.assertRaises(ValueError):
+ ast.parse('pass', feature_version=(2, 7))
+ with self.assertRaises(ValueError):
+ ast.parse('pass', feature_version=(4, 0))
+
def test_constant_as_name(self):
for constant in "True", "False", "None":
expr = ast.Expression(ast.Name(constant, ast.Load()))