Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add bare ExceptionGroup #5259

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 1 commit into from
Apr 23, 2024
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
16 changes: 0 additions & 16 deletions Lib/test/test_exception_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def test_bad_EG_construction__nested_non_exceptions(self):


class InstanceCreation(unittest.TestCase):
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_EG_wraps_Exceptions__creates_EG(self):
excs = [ValueError(1), TypeError(2)]
self.assertIs(
Expand All @@ -99,8 +97,6 @@ def test_BEG_wraps_BaseException__creates_BEG(self):
beg = BaseExceptionGroup("beg", [ValueError(1), KeyboardInterrupt(2)])
self.assertIs(type(beg), BaseExceptionGroup)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_EG_subclass_wraps_non_base_exceptions(self):
class MyEG(ExceptionGroup):
pass
Expand Down Expand Up @@ -245,8 +241,6 @@ def create_simple_eg():


class ExceptionGroupFields(unittest.TestCase):
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_basics_ExceptionGroup_fields(self):
eg = create_simple_eg()

Expand Down Expand Up @@ -510,8 +504,6 @@ class LeafGeneratorTest(unittest.TestCase):
# on how to iterate over leaf nodes of an EG. It is also
# used below as a test utility. So we test it here.

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_leaf_generator(self):
eg = create_simple_eg()

Expand Down Expand Up @@ -549,25 +541,19 @@ def create_nested_eg():


class NestedExceptionGroupBasicsTest(ExceptionGroupTestBase):
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_nested_group_matches_template(self):
eg = create_nested_eg()
self.assertMatchesTemplate(
eg,
ExceptionGroup,
[[TypeError(bytes)], ValueError(1)])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_nested_group_chaining(self):
eg = create_nested_eg()
self.assertIsInstance(eg.exceptions[1].__context__, MemoryError)
self.assertIsInstance(eg.exceptions[1].__cause__, MemoryError)
self.assertIsInstance(eg.exceptions[0].__context__, TypeError)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_nested_exception_group_tracebacks(self):
eg = create_nested_eg()

Expand All @@ -581,8 +567,6 @@ def test_nested_exception_group_tracebacks(self):
self.assertEqual(tb.tb_lineno, expected)
self.assertIsNone(tb.tb_next)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_iteration_full_tracebacks(self):
eg = create_nested_eg()
# check that iteration over leaves
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def test_exceptions(self):
StopAsyncIteration,
RecursionError,
EncodingWarning,
#ExceptionGroup, # TODO: RUSTPYTHON
ExceptionGroup,
BaseExceptionGroup):
continue
if exc is not OSError and issubclass(exc, OSError):
Expand Down
8 changes: 8 additions & 0 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl ExceptionCtor {
pub struct ExceptionZoo {
pub base_exception_type: &'static Py<PyType>,
pub base_exception_group: &'static Py<PyType>,
pub 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 @@ -560,6 +561,7 @@ impl ExceptionZoo {

// Sorted By Hierarchy then alphabetized.
let base_exception_group = PyBaseExceptionGroup::init_builtin_type();
let exception_group = PyExceptionGroup::init_builtin_type();
let system_exit = PySystemExit::init_builtin_type();
let keyboard_interrupt = PyKeyboardInterrupt::init_builtin_type();
let generator_exit = PyGeneratorExit::init_builtin_type();
Expand Down Expand Up @@ -646,6 +648,7 @@ impl ExceptionZoo {
Self {
base_exception_type,
base_exception_group,
exception_group,
system_exit,
keyboard_interrupt,
generator_exit,
Expand Down Expand Up @@ -731,6 +734,7 @@ impl ExceptionZoo {
"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!(PyExceptionGroup, ctx, excs.exception_group);
extend_exception!(PySystemExit, ctx, excs.system_exit, {
"code" => ctx.new_readonly_getset("code", excs.system_exit, system_exit_code),
});
Expand Down Expand Up @@ -1083,6 +1087,10 @@ pub(super) mod types {
#[derive(Debug)]
pub struct PyBaseExceptionGroup {}

#[pyexception(name, base = "PyBaseExceptionGroup", ctx = "exception_group", impl)]
#[derive(Debug)]
pub struct PyExceptionGroup {}

#[pyexception(name, base = "PyBaseException", ctx = "generator_exit", impl)]
#[derive(Debug)]
pub struct PyGeneratorExit {}
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 @@ -1006,6 +1006,7 @@ pub fn init_module(vm: &VirtualMachine, module: &Py<PyModule>) {
// Exceptions:
"BaseException" => ctx.exceptions.base_exception_type.to_owned(),
"BaseExceptionGroup" => ctx.exceptions.base_exception_group.to_owned(),
"ExceptionGroup" => ctx.exceptions.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