bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)

(cherry picked from commit 68874a8502)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-06-06 10:04:38 -07:00 committed by GitHub
parent 18f1226884
commit 90ee51f1cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View file

@ -668,6 +668,13 @@ class AST_Tests(unittest.TestCase):
with self.assertRaises(SyntaxError):
ast.parse('f"{x=}"', feature_version=(3, 7))
def test_constant_as_name(self):
for constant in "True", "False", "None":
expr = ast.Expression(ast.Name(constant, ast.Load()))
ast.fix_missing_locations(expr)
with self.assertRaisesRegex(ValueError, f"Name node can't be used with '{constant}' constant"):
compile(expr, "<test>", "eval")
class ASTHelpers_Test(unittest.TestCase):
maxDiff = None