Skip to content

Commit 14a42a4

Browse files
Make the error message for C-API interpreters less confusing.
1 parent cb84c1d commit 14a42a4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Lib/test/test_interpreters/test_api.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -717,18 +717,18 @@ def test_created_with_capi(self):
717717
with self.subTest('running __main__ (from self)'):
718718
with self.interpreter_from_capi() as interpid:
719719
with self.assertRaisesRegex(ExecutionFailed,
720-
'InterpreterError.*unrecognized'):
720+
'InterpreterError.*not supported'):
721721
self.run_from_capi(interpid, script, main=True)
722722

723723
with self.subTest('running, but not __main__ (from self)'):
724724
with self.assertRaisesRegex(ExecutionFailed,
725-
'InterpreterError.*unrecognized'):
725+
'InterpreterError.*not supported'):
726726
self.run_temp_from_capi(script)
727727

728728
with self.subTest('running __main__ (from other)'):
729729
with self.interpreter_obj_from_capi() as (interp, interpid):
730730
with self.running_from_capi(interpid, main=True):
731-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
731+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
732732
interp.close()
733733
# Make sure it wssn't closed.
734734
self.assertTrue(
@@ -741,15 +741,15 @@ def test_created_with_capi(self):
741741
with self.subTest('running, but not __main__ (from other)'):
742742
with self.interpreter_obj_from_capi() as (interp, interpid):
743743
with self.running_from_capi(interpid, main=False):
744-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
744+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
745745
interp.close()
746746
# Make sure it wssn't closed.
747747
self.assertTrue(
748748
self.interp_exists(interpid))
749749

750750
with self.subTest('not running (from other)'):
751751
with self.interpreter_obj_from_capi() as (interp, interpid):
752-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
752+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
753753
interp.close()
754754
self.assertTrue(
755755
self.interp_exists(interpid))
@@ -920,7 +920,7 @@ def test_running(self):
920920
@requires_test_modules
921921
def test_created_with_capi(self):
922922
with self.interpreter_obj_from_capi() as (interp, interpid):
923-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
923+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
924924
interp.prepare_main({'spam': True})
925925
with self.assertRaisesRegex(ExecutionFailed, 'NameError'):
926926
self.run_from_capi(interpid, 'assert spam is True')
@@ -1098,7 +1098,7 @@ def task():
10981098

10991099
def test_created_with_capi(self):
11001100
with self.interpreter_obj_from_capi() as (interp, _):
1101-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
1101+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
11021102
interp.exec('raise Exception("it worked!")')
11031103

11041104
def test_list_comprehension(self):
@@ -2271,7 +2271,7 @@ def test_destroy(self):
22712271

22722272
with self.subTest('from C-API'):
22732273
interpid = _testinternalcapi.create_interpreter()
2274-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
2274+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
22752275
_interpreters.destroy(interpid, restrict=True)
22762276
self.assertTrue(
22772277
self.interp_exists(interpid))
@@ -2315,7 +2315,7 @@ def test_get_config(self):
23152315
with self.subTest('from C-API'):
23162316
orig = _interpreters.new_config('isolated')
23172317
with self.interpreter_from_capi(orig) as interpid:
2318-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
2318+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
23192319
_interpreters.get_config(interpid, restrict=True)
23202320
config = _interpreters.get_config(interpid)
23212321
self.assert_ns_equal(config, orig)
@@ -2376,7 +2376,7 @@ def test_contextvars_missing(self):
23762376

23772377
def test_is_running(self):
23782378
def check(interpid, expected):
2379-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
2379+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
23802380
_interpreters.is_running(interpid, restrict=True)
23812381
running = _interpreters.is_running(interpid)
23822382
self.assertIs(running, expected)
@@ -2442,7 +2442,7 @@ def test_exec(self):
24422442

24432443
with self.subTest('from C-API'):
24442444
with self.interpreter_from_capi() as interpid:
2445-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
2445+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
24462446
_interpreters.exec(interpid, 'raise Exception("it worked!")',
24472447
restrict=True)
24482448
exc = _interpreters.exec(interpid, 'raise Exception("it worked!")')
@@ -2521,7 +2521,7 @@ def test_set___main___attrs(self):
25212521

25222522
with self.subTest('from C-API'):
25232523
with self.interpreter_from_capi() as interpid:
2524-
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
2524+
with self.assertRaisesRegex(InterpreterError, 'not supported'):
25252525
_interpreters.set___main___attrs(interpid, {'spam': True},
25262526
restrict=True)
25272527
_interpreters.set___main___attrs(interpid, {'spam': True})

Modules/_interpretersmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,11 @@ resolve_interp(PyObject *idobj, int restricted, int reqready, const char *op)
775775
if (restricted && get_whence(interp) != _PyInterpreterState_WHENCE_STDLIB) {
776776
if (idobj == NULL) {
777777
PyErr_Format(PyExc_InterpreterError,
778-
"cannot %s unrecognized current interpreter", op);
778+
"cannot %s current interpreter (not supported)", op);
779779
}
780780
else {
781781
PyErr_Format(PyExc_InterpreterError,
782-
"cannot %s unrecognized interpreter %R", op, idobj);
782+
"cannot %s interpreter %R (not supported)", op, idobj);
783783
}
784784
return NULL;
785785
}

0 commit comments

Comments
 (0)