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



diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index a3b366e..78e4a56 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -668,6 +668,13 @@
         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