gh-115376: fix segfault in _testinternalcapi.compiler_codegen on bad input (#115379)

This commit is contained in:
Irit Katriel 2024-02-15 14:32:21 +00:00 committed by GitHub
parent 94f1334e52
commit 3a9e67a9fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 15 deletions

View file

@ -8,7 +8,7 @@ class IsolatedCodeGenTests(CodegenTestCase):
def codegen_test(self, snippet, expected_insts):
import ast
a = ast.parse(snippet, "my_file.py", "exec");
a = ast.parse(snippet, "my_file.py", "exec")
insts = self.generate_code(a)
self.assertInstructionsMatch(insts, expected_insts)
@ -54,3 +54,8 @@ class IsolatedCodeGenTests(CodegenTestCase):
('RETURN_VALUE', None),
]
self.codegen_test(snippet, expected)
def test_syntax_error__return_not_in_function(self):
snippet = "return 42"
with self.assertRaisesRegex(SyntaxError, "'return' outside function"):
self.codegen_test(snippet, None)