import unittest
from test import support
+from test.support.script_helper import assert_python_ok
class SyntaxWarningTest(unittest.TestCase):
def check_warning(self, code, errtext, filename="<testcase>", mode="exec"):
class B[{name}]: pass
""", "<testcase>", mode="exec")
+ @support.nomemtest
+ def test_disallowed_type_param_names_oom(self):
+ # gh-152682: Don't crash on OOM when formatting the SyntaxError message
+ # in symtable_visit_type_param_bound_or_default.
+ code = textwrap.dedent("""\
+ import _testcapi
+ _testcapi.set_nomemory(0)
+ try:
+ compile("class A[__classdict__]: pass", "<string>", "exec")
+ except MemoryError:
+ pass
+ else:
+ raise RuntimeError('MemoryError not raised')
+ """)
+ assert_python_ok("-c", code)
+
@support.cpython_only
def test_nested_named_except_blocks(self):
code = ""
PyObject *error_msg = PyUnicode_FromFormat("reserved name '%U' cannot be "
"used for type parameter", name);
+ if (error_msg == NULL) {
+ return 0;
+ }
PyErr_SetObject(PyExc_SyntaxError, error_msg);
Py_DECREF(error_msg);
SET_ERROR_LOCATION(st->st_filename, LOCATION(tp));