FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.10] gh-90494: Reject 6th element of the __reduce__() tuple (GH-93609) by miss-islington · Pull Request #93632 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Lib/copy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _keep_alive(x, memo):

def _reconstruct(x, memo, func, args,
state=None, listiter=None, dictiter=None,
deepcopy=deepcopy):
*, deepcopy=deepcopy):
Comment thread
ambv marked this conversation as resolved.
deep = memo is not None
if deep and args:
args = (deepcopy(arg, memo) for arg in args)
Expand Down
2 changes: 1 addition & 1 deletion Lib/pickle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def save_pers(self, pid):
"persistent IDs in protocol 0 must be ASCII strings")

def save_reduce(self, func, args, state=None, listitems=None,
dictitems=None, state_setter=None, obj=None):
dictitems=None, state_setter=None, *, obj=None):
# This API is called by some subclasses

if not isinstance(args, tuple):
Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_copy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,28 @@ def __eq__(self, other):
self.assertIsNot(x, y)
self.assertIsNot(x["foo"], y["foo"])

def test_reduce_6tuple(self):
def state_setter(*args, **kwargs):
self.fail("shouldn't call this")
class C:
def __reduce__(self):
return C, (), self.__dict__, None, None, state_setter
x = C()
with self.assertRaises(TypeError):
copy.copy(x)
with self.assertRaises(TypeError):
copy.deepcopy(x)

def test_reduce_6tuple_none(self):
class C:
def __reduce__(self):
return C, (), self.__dict__, None, None, None
x = C()
with self.assertRaises(TypeError):
copy.copy(x)
with self.assertRaises(TypeError):
copy.deepcopy(x)

def test_copy_slots(self):
class C(object):
__slots__ = ["foo"]
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`copy.copy` and :func:`copy.deepcopy` now always raise a TypeError if
``__reduce__()`` returns a tuple with length 6 instead of silently ignore
the 6th item or produce incorrect result.

Back | FazBrowse Home | New Git URL