mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
18f1226884
commit
90ee51f1cd
3 changed files with 31 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue