mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-29914: Fix default implementations of __reduce__ and __reduce_ex__(). (#843)
object.__reduce__() no longer takes arguments, object.__reduce_ex__() now requires one argument.
This commit is contained in:
parent
dd9a0a14c8
commit
205e00c5cf
4 changed files with 34 additions and 39 deletions
|
@ -5236,7 +5236,20 @@ class PicklingTests(unittest.TestCase):
|
|||
|
||||
import copyreg
|
||||
expected = (copyreg.__newobj__, (A,), (None, {'spam': 42}), None, None)
|
||||
self.assertEqual(A().__reduce__(2), expected) # Shouldn't crash
|
||||
self.assertEqual(A().__reduce_ex__(2), expected) # Shouldn't crash
|
||||
|
||||
def test_object_reduce(self):
|
||||
# Issue #29914
|
||||
# __reduce__() takes no arguments
|
||||
object().__reduce__()
|
||||
with self.assertRaises(TypeError):
|
||||
object().__reduce__(0)
|
||||
# __reduce_ex__() takes one integer argument
|
||||
object().__reduce_ex__(0)
|
||||
with self.assertRaises(TypeError):
|
||||
object().__reduce_ex__()
|
||||
with self.assertRaises(TypeError):
|
||||
object().__reduce_ex__(None)
|
||||
|
||||
|
||||
class SharedKeyTests(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue