forked from Rust-related/RustPython
Add bare ExceptionGroup (#5259)
This commit is contained in:
16
Lib/test/test_exception_group.py
vendored
16
Lib/test/test_exception_group.py
vendored
@@ -72,8 +72,6 @@ class BadConstructorArgs(unittest.TestCase):
|
||||
|
||||
|
||||
class InstanceCreation(unittest.TestCase):
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_EG_wraps_Exceptions__creates_EG(self):
|
||||
excs = [ValueError(1), TypeError(2)]
|
||||
self.assertIs(
|
||||
@@ -99,8 +97,6 @@ class InstanceCreation(unittest.TestCase):
|
||||
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
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -549,8 +541,6 @@ def create_nested_eg():
|
||||
|
||||
|
||||
class NestedExceptionGroupBasicsTest(ExceptionGroupTestBase):
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_nested_group_matches_template(self):
|
||||
eg = create_nested_eg()
|
||||
self.assertMatchesTemplate(
|
||||
@@ -558,16 +548,12 @@ class NestedExceptionGroupBasicsTest(ExceptionGroupTestBase):
|
||||
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()
|
||||
|
||||
@@ -581,8 +567,6 @@ class NestedExceptionGroupBasicsTest(ExceptionGroupTestBase):
|
||||
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
|
||||
|
||||
2
Lib/test/test_pickle.py
vendored
2
Lib/test/test_pickle.py
vendored
@@ -633,7 +633,7 @@ class CompatPickleTests(unittest.TestCase):
|
||||
StopAsyncIteration,
|
||||
RecursionError,
|
||||
EncodingWarning,
|
||||
#ExceptionGroup, # TODO: RUSTPYTHON
|
||||
ExceptionGroup,
|
||||
BaseExceptionGroup):
|
||||
continue
|
||||
if exc is not OSError and issubclass(exc, OSError):
|
||||
|
||||
@@ -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>,
|
||||
@@ -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();
|
||||
@@ -646,6 +648,7 @@ impl ExceptionZoo {
|
||||
Self {
|
||||
base_exception_type,
|
||||
base_exception_group,
|
||||
exception_group,
|
||||
system_exit,
|
||||
keyboard_interrupt,
|
||||
generator_exit,
|
||||
@@ -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),
|
||||
});
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user