mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-40000: Improve error messages when validating invalid ast.Constant nodes (GH-19055)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
parent
50e6e99178
commit
0ac59f93c0
3 changed files with 16 additions and 3 deletions
|
@ -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()")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue