summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2020-03-19 11:32:28 (GMT)
committerGitHub <noreply@github.com>2020-03-19 11:32:28 (GMT)
commit0ac59f93c0e3f91fd994d7245578cce65654fb22 (patch)
treec1eab66af2739b9b8aa257b082fac7b732a55983 /Lib
parent50e6e991781db761c496561a995541ca8d83ff87 (diff)
downloadcpython-0ac59f93c0e3f91fd994d7245578cce65654fb22.zip
cpython-0ac59f93c0e3f91fd994d7245578cce65654fb22.tar.gz
cpython-0ac59f93c0e3f91fd994d7245578cce65654fb22.tar.bz2
bpo-40000: Improve error messages when validating invalid ast.Constant nodes (GH-19055)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_ast.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 66f8384..d072c33 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -582,6 +582,15 @@ class AST_Tests(unittest.TestCase):
compile(m, "<test>", "exec")
self.assertIn("identifier must be of type str", str(cm.exception))
+ def test_invalid_constant(self):
+ for invalid_constant in int, (1, 2, int), frozenset((1, 2, int)):
+ e = ast.Expression(body=ast.Constant(invalid_constant))
+ ast.fix_missing_locations(e)
+ with self.assertRaisesRegex(
+ TypeError, "invalid type in Constant: type"
+ ):
+ compile(e, "<test>", "eval")
+
def test_empty_yield_from(self):
# Issue 16546: yield from value is not optional.
empty_yield_from = ast.parse("def f():\n yield from g()")