Skip to content

gh-76785: Raise InterpreterError, Not RuntimeError #117489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Raise InterpreterError instead of RuntimeError.
  • Loading branch information
ericsnowcurrently committed Apr 2, 2024
commit d048d7737403f4d3e3cd25633123f6ff5f49052c
4 changes: 2 additions & 2 deletions Lib/test/support/interpreters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __getattr__(name):
{formatted}
""".strip()

class ExecutionFailed(RuntimeError):
class ExecutionFailed(InterpreterError):
"""An unhandled exception happened during execution.

This is raised from Interpreter.exec() and Interpreter.call().
Expand Down Expand Up @@ -158,7 +158,7 @@ def close(self):
"""Finalize and destroy the interpreter.

Attempting to destroy the current interpreter results
in a RuntimeError.
in an InterpreterError.
"""
return _interpreters.destroy(self._id)

Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ def test_all(self):

def test_main(self):
main, = interpreters.list_all()
with self.assertRaises(RuntimeError):
with self.assertRaises(interpreters.InterpreterError):
main.close()

def f():
with self.assertRaises(RuntimeError):
with self.assertRaises(interpreters.InterpreterError):
main.close()

t = threading.Thread(target=f)
Expand All @@ -389,7 +389,7 @@ def test_from_current(self):
interp = interpreters.Interpreter({interp.id})
try:
interp.close()
except RuntimeError:
except interpreters.InterpreterError:
print('failed')
"""))
self.assertEqual(out.strip(), 'failed')
Expand Down Expand Up @@ -424,7 +424,7 @@ def test_still_running(self):
main, = interpreters.list_all()
interp = interpreters.create()
with _running(interp):
with self.assertRaises(RuntimeError):
with self.assertRaises(interpreters.InterpreterError):
interp.close()
self.assertTrue(interp.is_running())

Expand Down Expand Up @@ -1103,7 +1103,7 @@ def test_create(self):
self.assert_ns_equal(config, default)

with self.subTest('arg: \'empty\''):
with self.assertRaises(RuntimeError):
with self.assertRaises(interpreters.InterpreterError):
# The "empty" config isn't viable on its own.
_interpreters.create('empty')

Expand Down
8 changes: 4 additions & 4 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ interp_create(PyObject *self, PyObject *args, PyObject *kwds)
// XXX Move the chained exception to interpreters.create()?
PyObject *exc = PyErr_GetRaisedException();
assert(exc != NULL);
PyErr_SetString(PyExc_RuntimeError, "interpreter creation failed");
PyErr_SetString(PyExc_InterpreterError, "interpreter creation failed");
_PyErr_ChainExceptions1(exc);
return NULL;
}
Expand Down Expand Up @@ -664,7 +664,7 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
}
if (interp == current) {
PyErr_SetString(PyExc_RuntimeError,
PyErr_SetString(PyExc_InterpreterError,
"cannot destroy the current interpreter");
return NULL;
}
Expand All @@ -673,7 +673,7 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
/* XXX We *could* support destroying a running interpreter but
aren't going to worry about it for now. */
if (is_running_main(interp)) {
PyErr_Format(PyExc_RuntimeError, "interpreter running");
PyErr_Format(PyExc_InterpreterError, "interpreter running");
return NULL;
}

Expand All @@ -693,7 +693,7 @@ PyDoc_STRVAR(destroy_doc,
\n\
Destroy the identified interpreter.\n\
\n\
Attempting to destroy the current interpreter results in a RuntimeError.\n\
Attempting to destroy the current interpreter raises InterpreterError.\n\
So does an unrecognized ID.");


Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy