diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index d2cfd08cc89..84499689e12 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -1703,8 +1703,6 @@ def test_inconsistent_converters_state(self): class ExceptionPicklingTestCase(unittest.TestCase): """Tests for issue #13760: ConfigParser exceptions are not picklable.""" - # TODO: RUSTPYTHON Exception.__reduce__ missing. - @unittest.expectedFailure def test_error(self): import pickle e1 = configparser.Error('value') @@ -1714,8 +1712,6 @@ def test_error(self): self.assertEqual(e1.message, e2.message) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_nosectionerror(self): import pickle e1 = configparser.NoSectionError('section') @@ -1727,8 +1723,6 @@ def test_nosectionerror(self): self.assertEqual(e1.section, e2.section) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_nooptionerror(self): import pickle e1 = configparser.NoOptionError('option', 'section') @@ -1741,8 +1735,6 @@ def test_nooptionerror(self): self.assertEqual(e1.option, e2.option) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_duplicatesectionerror(self): import pickle e1 = configparser.DuplicateSectionError('section', 'source', 123) @@ -1756,8 +1748,6 @@ def test_duplicatesectionerror(self): self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_duplicateoptionerror(self): import pickle e1 = configparser.DuplicateOptionError('section', 'option', 'source', @@ -1773,8 +1763,6 @@ def test_duplicateoptionerror(self): self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_interpolationerror(self): import pickle e1 = configparser.InterpolationError('option', 'section', 'msg') @@ -1787,8 +1775,6 @@ def test_interpolationerror(self): self.assertEqual(e1.option, e2.option) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_interpolationmissingoptionerror(self): import pickle e1 = configparser.InterpolationMissingOptionError('option', 'section', @@ -1803,8 +1789,6 @@ def test_interpolationmissingoptionerror(self): self.assertEqual(e1.reference, e2.reference) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_interpolationsyntaxerror(self): import pickle e1 = configparser.InterpolationSyntaxError('option', 'section', 'msg') @@ -1817,8 +1801,6 @@ def test_interpolationsyntaxerror(self): self.assertEqual(e1.option, e2.option) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_interpolationdeptherror(self): import pickle e1 = configparser.InterpolationDepthError('option', 'section', @@ -1832,8 +1814,6 @@ def test_interpolationdeptherror(self): self.assertEqual(e1.option, e2.option) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_parsingerror(self): import pickle e1 = configparser.ParsingError('source') @@ -1861,8 +1841,6 @@ def test_parsingerror(self): self.assertEqual(e1.errors, e2.errors) self.assertEqual(repr(e1), repr(e2)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_missingsectionheadererror(self): import pickle e1 = configparser.MissingSectionHeaderError('filename', 123, 'line') diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 8a67c51bde3..b3e3897ca36 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1923,8 +1923,6 @@ def test_non_str_argument(self): exc = ImportError(arg) self.assertEqual(str(arg), str(exc)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_copy_pickle(self): for kwargs in (dict(), dict(name='somename'), diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py index 16d2f76a8c7..a4193d71bad 100644 --- a/Lib/unittest/test/test_discovery.py +++ b/Lib/unittest/test/test_discovery.py @@ -499,8 +499,6 @@ def test_discover_with_modules_that_fail_to_import(self): with self.assertRaises(ImportError): test.test_this_does_not_exist() - # TODO: RUSTPYTHON ImportError.__reduce__ missing - @unittest.expectedFailure def test_discover_with_init_modules_that_fail_to_import(self): vfs = {abspath('/foo'): ['my_package'], abspath('/foo/my_package'): ['__init__.py', 'test_module.py']} diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 272251591e5..6fe2da677ef 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -519,6 +519,15 @@ impl PyBaseException { let cls = zelf.class(); format!("{}({})", cls.name(), repr_args.iter().format(", ")) } + + #[pymethod(magic)] + fn reduce(zelf: PyRef, vm: &VirtualMachine) -> PyTupleRef { + if let Some(dict) = zelf.as_object().dict().filter(|x| !x.is_empty()) { + return vm.new_tuple((zelf.class().clone(), zelf.args(), dict)); + } else { + return vm.new_tuple((zelf.class().clone(), zelf.args())); + } + } } impl ExceptionZoo {