summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-07-22 15:50:23 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-07-22 15:50:23 (GMT)
commit2193d2b72bc942a0c0b489a9c2759a6aefbeecdf (patch)
tree76d553c58f5e909d09aef21e6131ec797e72c3d7 /Lib
parent996f606787a7aba177f738157acd672b5821be4c (diff)
downloadcpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.zip
cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.tar.gz
cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.tar.bz2
type check AST strings and identifiers
This is related to a21829180423 as well as #12609 and #12610.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_ast.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 13ec2d0..7d1649c 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -364,6 +364,20 @@ class AST_Tests(unittest.TestCase):
compile(m, "<test>", "exec")
self.assertIn("but got <_ast.expr", str(cm.exception))
+ def test_invalid_identitifer(self):
+ m = ast.Module([ast.Expr(ast.Name(42, ast.Load()))])
+ ast.fix_missing_locations(m)
+ with self.assertRaises(TypeError) as cm:
+ compile(m, "<test>", "exec")
+ self.assertIn("identifier must be of type str", str(cm.exception))
+
+ def test_invalid_string(self):
+ m = ast.Module([ast.Expr(ast.Str(42))])
+ ast.fix_missing_locations(m)
+ with self.assertRaises(TypeError) as cm:
+ compile(m, "<test>", "exec")
+ self.assertIn("string must be of type str", str(cm.exception))
+
class ASTHelpers_Test(unittest.TestCase):