Skip to content

Commit 4c39668

Browse files
authored
Merge pull request #3665 from fanninpm/baseexception-reduce
Add BaseException.__reduce__
2 parents a3fab06 + dfbd8dc commit 4c39668

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

Lib/test/test_configparser.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,6 @@ def test_inconsistent_converters_state(self):
17031703
class ExceptionPicklingTestCase(unittest.TestCase):
17041704
"""Tests for issue #13760: ConfigParser exceptions are not picklable."""
17051705

1706-
# TODO: RUSTPYTHON Exception.__reduce__ missing.
1707-
@unittest.expectedFailure
17081706
def test_error(self):
17091707
import pickle
17101708
e1 = configparser.Error('value')
@@ -1714,8 +1712,6 @@ def test_error(self):
17141712
self.assertEqual(e1.message, e2.message)
17151713
self.assertEqual(repr(e1), repr(e2))
17161714

1717-
# TODO: RUSTPYTHON
1718-
@unittest.expectedFailure
17191715
def test_nosectionerror(self):
17201716
import pickle
17211717
e1 = configparser.NoSectionError('section')
@@ -1727,8 +1723,6 @@ def test_nosectionerror(self):
17271723
self.assertEqual(e1.section, e2.section)
17281724
self.assertEqual(repr(e1), repr(e2))
17291725

1730-
# TODO: RUSTPYTHON
1731-
@unittest.expectedFailure
17321726
def test_nooptionerror(self):
17331727
import pickle
17341728
e1 = configparser.NoOptionError('option', 'section')
@@ -1741,8 +1735,6 @@ def test_nooptionerror(self):
17411735
self.assertEqual(e1.option, e2.option)
17421736
self.assertEqual(repr(e1), repr(e2))
17431737

1744-
# TODO: RUSTPYTHON
1745-
@unittest.expectedFailure
17461738
def test_duplicatesectionerror(self):
17471739
import pickle
17481740
e1 = configparser.DuplicateSectionError('section', 'source', 123)
@@ -1756,8 +1748,6 @@ def test_duplicatesectionerror(self):
17561748
self.assertEqual(e1.lineno, e2.lineno)
17571749
self.assertEqual(repr(e1), repr(e2))
17581750

1759-
# TODO: RUSTPYTHON
1760-
@unittest.expectedFailure
17611751
def test_duplicateoptionerror(self):
17621752
import pickle
17631753
e1 = configparser.DuplicateOptionError('section', 'option', 'source',
@@ -1773,8 +1763,6 @@ def test_duplicateoptionerror(self):
17731763
self.assertEqual(e1.lineno, e2.lineno)
17741764
self.assertEqual(repr(e1), repr(e2))
17751765

1776-
# TODO: RUSTPYTHON
1777-
@unittest.expectedFailure
17781766
def test_interpolationerror(self):
17791767
import pickle
17801768
e1 = configparser.InterpolationError('option', 'section', 'msg')
@@ -1787,8 +1775,6 @@ def test_interpolationerror(self):
17871775
self.assertEqual(e1.option, e2.option)
17881776
self.assertEqual(repr(e1), repr(e2))
17891777

1790-
# TODO: RUSTPYTHON
1791-
@unittest.expectedFailure
17921778
def test_interpolationmissingoptionerror(self):
17931779
import pickle
17941780
e1 = configparser.InterpolationMissingOptionError('option', 'section',
@@ -1803,8 +1789,6 @@ def test_interpolationmissingoptionerror(self):
18031789
self.assertEqual(e1.reference, e2.reference)
18041790
self.assertEqual(repr(e1), repr(e2))
18051791

1806-
# TODO: RUSTPYTHON
1807-
@unittest.expectedFailure
18081792
def test_interpolationsyntaxerror(self):
18091793
import pickle
18101794
e1 = configparser.InterpolationSyntaxError('option', 'section', 'msg')
@@ -1817,8 +1801,6 @@ def test_interpolationsyntaxerror(self):
18171801
self.assertEqual(e1.option, e2.option)
18181802
self.assertEqual(repr(e1), repr(e2))
18191803

1820-
# TODO: RUSTPYTHON
1821-
@unittest.expectedFailure
18221804
def test_interpolationdeptherror(self):
18231805
import pickle
18241806
e1 = configparser.InterpolationDepthError('option', 'section',
@@ -1832,8 +1814,6 @@ def test_interpolationdeptherror(self):
18321814
self.assertEqual(e1.option, e2.option)
18331815
self.assertEqual(repr(e1), repr(e2))
18341816

1835-
# TODO: RUSTPYTHON
1836-
@unittest.expectedFailure
18371817
def test_parsingerror(self):
18381818
import pickle
18391819
e1 = configparser.ParsingError('source')
@@ -1861,8 +1841,6 @@ def test_parsingerror(self):
18611841
self.assertEqual(e1.errors, e2.errors)
18621842
self.assertEqual(repr(e1), repr(e2))
18631843

1864-
# TODO: RUSTPYTHON
1865-
@unittest.expectedFailure
18661844
def test_missingsectionheadererror(self):
18671845
import pickle
18681846
e1 = configparser.MissingSectionHeaderError('filename', 123, 'line')

Lib/test/test_exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,8 +1923,6 @@ def test_non_str_argument(self):
19231923
exc = ImportError(arg)
19241924
self.assertEqual(str(arg), str(exc))
19251925

1926-
# TODO: RUSTPYTHON
1927-
@unittest.expectedFailure
19281926
def test_copy_pickle(self):
19291927
for kwargs in (dict(),
19301928
dict(name='somename'),

Lib/unittest/test/test_discovery.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ def test_discover_with_modules_that_fail_to_import(self):
499499
with self.assertRaises(ImportError):
500500
test.test_this_does_not_exist()
501501

502-
# TODO: RUSTPYTHON ImportError.__reduce__ missing
503-
@unittest.expectedFailure
504502
def test_discover_with_init_modules_that_fail_to_import(self):
505503
vfs = {abspath('/foo'): ['my_package'],
506504
abspath('/foo/my_package'): ['__init__.py', 'test_module.py']}

vm/src/exceptions.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,15 @@ impl PyBaseException {
519519
let cls = zelf.class();
520520
format!("{}({})", cls.name(), repr_args.iter().format(", "))
521521
}
522+
523+
#[pymethod(magic)]
524+
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyTupleRef {
525+
if let Some(dict) = zelf.as_object().dict().filter(|x| !x.is_empty()) {
526+
return vm.new_tuple((zelf.class().clone(), zelf.args(), dict));
527+
} else {
528+
return vm.new_tuple((zelf.class().clone(), zelf.args()));
529+
}
530+
}
522531
}
523532

524533
impl ExceptionZoo {

0 commit comments

Comments
 (0)