summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-06 17:04:47 (GMT)
committerGitHub <noreply@github.com>2020-06-06 17:04:47 (GMT)
commit83a9ba442662c2a030b45955f3dd24ff4b24bb61 (patch)
tree022cecd992bd8af026d0ada3ca8142187db420fc /Lib/test
parentf7ed4d4e83f5d9e85e244a1cbc460f26436ab24d (diff)
downloadcpython-83a9ba442662c2a030b45955f3dd24ff4b24bb61.zip
cpython-83a9ba442662c2a030b45955f3dd24ff4b24bb61.tar.gz
cpython-83a9ba442662c2a030b45955f3dd24ff4b24bb61.tar.bz2
bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)
(cherry picked from commit 68874a8502da440a1dc4746cf73262648b870aee) Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ast.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 8693466..b921f4a 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -635,6 +635,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