Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make the error message for C-API interpreters less confusing.
  • Loading branch information
ericsnowcurrently committed Oct 2, 2025
commit 14a42a43ad9ba586524c4769b1cdc68c71270c43
24 changes: 12 additions & 12 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,18 @@ def test_created_with_capi(self):
with self.subTest('running __main__ (from self)'):
with self.interpreter_from_capi() as interpid:
with self.assertRaisesRegex(ExecutionFailed,
'InterpreterError.*unrecognized'):
'InterpreterError.*not supported'):
self.run_from_capi(interpid, script, main=True)

with self.subTest('running, but not __main__ (from self)'):
with self.assertRaisesRegex(ExecutionFailed,
'InterpreterError.*unrecognized'):
'InterpreterError.*not supported'):
self.run_temp_from_capi(script)

with self.subTest('running __main__ (from other)'):
with self.interpreter_obj_from_capi() as (interp, interpid):
with self.running_from_capi(interpid, main=True):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
interp.close()
# Make sure it wssn't closed.
self.assertTrue(
Expand All @@ -741,15 +741,15 @@ def test_created_with_capi(self):
with self.subTest('running, but not __main__ (from other)'):
with self.interpreter_obj_from_capi() as (interp, interpid):
with self.running_from_capi(interpid, main=False):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
interp.close()
# Make sure it wssn't closed.
self.assertTrue(
self.interp_exists(interpid))

with self.subTest('not running (from other)'):
with self.interpreter_obj_from_capi() as (interp, interpid):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
interp.close()
self.assertTrue(
self.interp_exists(interpid))
Expand Down Expand Up @@ -920,7 +920,7 @@ def test_running(self):
@requires_test_modules
def test_created_with_capi(self):
with self.interpreter_obj_from_capi() as (interp, interpid):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
interp.prepare_main({'spam': True})
with self.assertRaisesRegex(ExecutionFailed, 'NameError'):
self.run_from_capi(interpid, 'assert spam is True')
Expand Down Expand Up @@ -1098,7 +1098,7 @@ def task():

def test_created_with_capi(self):
with self.interpreter_obj_from_capi() as (interp, _):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
interp.exec('raise Exception("it worked!")')

def test_list_comprehension(self):
Expand Down Expand Up @@ -2271,7 +2271,7 @@ def test_destroy(self):

with self.subTest('from C-API'):
interpid = _testinternalcapi.create_interpreter()
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
_interpreters.destroy(interpid, restrict=True)
self.assertTrue(
self.interp_exists(interpid))
Expand Down Expand Up @@ -2315,7 +2315,7 @@ def test_get_config(self):
with self.subTest('from C-API'):
orig = _interpreters.new_config('isolated')
with self.interpreter_from_capi(orig) as interpid:
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
_interpreters.get_config(interpid, restrict=True)
config = _interpreters.get_config(interpid)
self.assert_ns_equal(config, orig)
Expand Down Expand Up @@ -2376,7 +2376,7 @@ def test_contextvars_missing(self):

def test_is_running(self):
def check(interpid, expected):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
_interpreters.is_running(interpid, restrict=True)
running = _interpreters.is_running(interpid)
self.assertIs(running, expected)
Expand Down Expand Up @@ -2442,7 +2442,7 @@ def test_exec(self):

with self.subTest('from C-API'):
with self.interpreter_from_capi() as interpid:
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
_interpreters.exec(interpid, 'raise Exception("it worked!")',
restrict=True)
exc = _interpreters.exec(interpid, 'raise Exception("it worked!")')
Expand Down Expand Up @@ -2521,7 +2521,7 @@ def test_set___main___attrs(self):

with self.subTest('from C-API'):
with self.interpreter_from_capi() as interpid:
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
with self.assertRaisesRegex(InterpreterError, 'not supported'):
_interpreters.set___main___attrs(interpid, {'spam': True},
restrict=True)
_interpreters.set___main___attrs(interpid, {'spam': True})
Expand Down
4 changes: 2 additions & 2 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,11 @@ resolve_interp(PyObject *idobj, int restricted, int reqready, const char *op)
if (restricted && get_whence(interp) != _PyInterpreterState_WHENCE_STDLIB) {
if (idobj == NULL) {
PyErr_Format(PyExc_InterpreterError,
"cannot %s unrecognized current interpreter", op);
"cannot %s current interpreter (not supported)", op);
}
else {
PyErr_Format(PyExc_InterpreterError,
"cannot %s unrecognized interpreter %R", op, idobj);
"cannot %s interpreter %R (not supported)", op, idobj);
}
return NULL;
}
Expand Down