We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
run_mod
1 parent 37e4e20 commit 124259fCopy full SHA for 124259f
2 files changed
Lib/test/test_cmd_line_script.py
@@ -684,6 +684,17 @@ def test_syntaxerror_null_bytes_in_multiline_string(self):
684
]
685
)
686
687
+ def test_syntaxerror_does_not_crash(self):
688
+ script = "nonlocal x\n"
689
+ with os_helper.temp_dir() as script_dir:
690
+ script_name = _make_test_script(script_dir, 'script', script)
691
+ exitcode, stdout, stderr = assert_python_failure(script_name)
692
+ text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
693
+ # It used to crash in https://github.com/python/cpython/issues/111132
694
+ self.assertTrue(text.endswith(
695
+ 'SyntaxError: nonlocal declaration not allowed at module level\n',
696
+ ), text)
697
+
698
def test_consistent_sys_path_for_direct_execution(self):
699
# This test case ensures that the following all give the same
700
# sys.path configuration:
Python/pythonrun.c
@@ -1277,7 +1277,9 @@ run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
1277
1278
PyCodeObject *co = _PyAST_Compile(mod, interactive_filename, flags, -1, arena);
1279
if (co == NULL) {
1280
- Py_DECREF(interactive_filename);
+ if (interactive_src) {
1281
+ Py_DECREF(interactive_filename);
1282
+ }
1283
return NULL;
1284
}
1285
0 commit comments