Skip to content

Commit 415cdb1

Browse files
authored
Merge pull request #4681 from abyesilyurt/aziz/base_exc_group
Add BaseExceptionGroup
2 parents 17c5361 + 6cf99b4 commit 415cdb1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/test/test_pickle.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ def test_exceptions(self):
632632
ResourceWarning,
633633
StopAsyncIteration,
634634
RecursionError,
635-
EncodingWarning):
635+
EncodingWarning,
636+
#ExceptionGroup, # TODO: RUSTPYTHON
637+
BaseExceptionGroup):
636638
continue
637639
if exc is not OSError and issubclass(exc, OSError):
638640
self.assertEqual(reverse_mapping('builtins', name),

vm/src/exceptions.rs

+13
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ impl ExceptionCtor {
322322
#[derive(Debug, Clone)]
323323
pub struct ExceptionZoo {
324324
pub base_exception_type: &'static Py<PyType>,
325+
pub base_exception_group: &'static Py<PyType>,
325326
pub system_exit: &'static Py<PyType>,
326327
pub keyboard_interrupt: &'static Py<PyType>,
327328
pub generator_exit: &'static Py<PyType>,
@@ -538,6 +539,7 @@ impl ExceptionZoo {
538539
let base_exception_type = PyBaseException::init_bare_type();
539540

540541
// Sorted By Hierarchy then alphabetized.
542+
let base_exception_group = PyBaseExceptionGroup::init_bare_type();
541543
let system_exit = PySystemExit::init_bare_type();
542544
let keyboard_interrupt = PyKeyboardInterrupt::init_bare_type();
543545
let generator_exit = PyGeneratorExit::init_bare_type();
@@ -623,6 +625,7 @@ impl ExceptionZoo {
623625

624626
Self {
625627
base_exception_type,
628+
base_exception_group,
626629
system_exit,
627630
keyboard_interrupt,
628631
generator_exit,
@@ -704,6 +707,10 @@ impl ExceptionZoo {
704707
PyBaseException::extend_class(ctx, excs.base_exception_type);
705708

706709
// Sorted By Hierarchy then alphabetized.
710+
extend_exception!(PyBaseExceptionGroup, ctx, excs.base_exception_group, {
711+
"message" => ctx.new_readonly_getset("message", excs.base_exception_group, make_arg_getter(0)),
712+
"exceptions" => ctx.new_readonly_getset("exceptions", excs.base_exception_group, make_arg_getter(1)),
713+
});
707714
extend_exception!(PySystemExit, ctx, excs.system_exit, {
708715
"code" => ctx.new_readonly_getset("code", excs.system_exit, system_exit_code),
709716
});
@@ -1139,6 +1146,12 @@ pub(super) mod types {
11391146
system_exit,
11401147
"Request to exit from the interpreter."
11411148
}
1149+
define_exception! {
1150+
PyBaseExceptionGroup,
1151+
PyBaseException,
1152+
base_exception_group,
1153+
"A combination of multiple unrelated exceptions."
1154+
}
11421155
define_exception! {
11431156
PyGeneratorExit,
11441157
PyBaseException,

vm/src/stdlib/builtins.rs

+1
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
994994
// ordered by exception_hierarchy.txt
995995
// Exceptions:
996996
"BaseException" => ctx.exceptions.base_exception_type.to_owned(),
997+
"BaseExceptionGroup" => ctx.exceptions.base_exception_group.to_owned(),
997998
"SystemExit" => ctx.exceptions.system_exit.to_owned(),
998999
"KeyboardInterrupt" => ctx.exceptions.keyboard_interrupt.to_owned(),
9991000
"GeneratorExit" => ctx.exceptions.generator_exit.to_owned(),

0 commit comments

Comments
 (0)