Skip to content

Add BaseExceptionGroup #4681

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
merged 3 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion Lib/test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,9 @@ def test_exceptions(self):
ResourceWarning,
StopAsyncIteration,
RecursionError,
EncodingWarning):
EncodingWarning,
#ExceptionGroup, # TODO: RUSTPYTHON
BaseExceptionGroup):
continue
if exc is not OSError and issubclass(exc, OSError):
self.assertEqual(reverse_mapping('builtins', name),
Expand Down
13 changes: 13 additions & 0 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl ExceptionCtor {
#[derive(Debug, Clone)]
pub struct ExceptionZoo {
pub base_exception_type: &'static Py<PyType>,
pub base_exception_group: &'static Py<PyType>,
pub system_exit: &'static Py<PyType>,
pub keyboard_interrupt: &'static Py<PyType>,
pub generator_exit: &'static Py<PyType>,
Expand Down Expand Up @@ -538,6 +539,7 @@ impl ExceptionZoo {
let base_exception_type = PyBaseException::init_bare_type();

// Sorted By Hierarchy then alphabetized.
let base_exception_group = PyBaseExceptionGroup::init_bare_type();
let system_exit = PySystemExit::init_bare_type();
let keyboard_interrupt = PyKeyboardInterrupt::init_bare_type();
let generator_exit = PyGeneratorExit::init_bare_type();
Expand Down Expand Up @@ -623,6 +625,7 @@ impl ExceptionZoo {

Self {
base_exception_type,
base_exception_group,
system_exit,
keyboard_interrupt,
generator_exit,
Expand Down Expand Up @@ -704,6 +707,10 @@ impl ExceptionZoo {
PyBaseException::extend_class(ctx, excs.base_exception_type);

// Sorted By Hierarchy then alphabetized.
extend_exception!(PyBaseExceptionGroup, ctx, excs.base_exception_group, {
"message" => ctx.new_readonly_getset("message", excs.base_exception_group, make_arg_getter(0)),
"exceptions" => ctx.new_readonly_getset("exceptions", excs.base_exception_group, make_arg_getter(1)),
});
extend_exception!(PySystemExit, ctx, excs.system_exit, {
"code" => ctx.new_readonly_getset("code", excs.system_exit, system_exit_code),
});
Expand Down Expand Up @@ -1139,6 +1146,12 @@ pub(super) mod types {
system_exit,
"Request to exit from the interpreter."
}
define_exception! {
PyBaseExceptionGroup,
PyBaseException,
base_exception_group,
"A combination of multiple unrelated exceptions."
}
define_exception! {
PyGeneratorExit,
PyBaseException,
Expand Down
1 change: 1 addition & 0 deletions vm/src/stdlib/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
// ordered by exception_hierarchy.txt
// Exceptions:
"BaseException" => ctx.exceptions.base_exception_type.to_owned(),
"BaseExceptionGroup" => ctx.exceptions.base_exception_group.to_owned(),
"SystemExit" => ctx.exceptions.system_exit.to_owned(),
"KeyboardInterrupt" => ctx.exceptions.keyboard_interrupt.to_owned(),
"GeneratorExit" => ctx.exceptions.generator_exit.to_owned(),
Expand Down