Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e311453b
Commit
e311453b
authored
Feb 06, 2003
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support __reduce__ returning a 4-tuple or 5-tuple.
parent
b183f6e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
Lib/copy.py
Lib/copy.py
+20
-1
Lib/test/test_copy.py
Lib/test/test_copy.py
+36
-0
No files found.
Lib/copy.py
View file @
e311453b
...
@@ -297,15 +297,34 @@ def _reconstruct(x, info, deep, memo=None):
...
@@ -297,15 +297,34 @@ def _reconstruct(x, info, deep, memo=None):
if
memo
is
None
:
if
memo
is
None
:
memo
=
{}
memo
=
{}
n
=
len
(
info
)
n
=
len
(
info
)
assert
n
in
(
2
,
3
)
assert
n
in
(
2
,
3
,
4
,
5
)
callable
,
args
=
info
[:
2
]
callable
,
args
=
info
[:
2
]
if
n
>
2
:
if
n
>
2
:
state
=
info
[
2
]
state
=
info
[
2
]
else
:
else
:
state
=
{}
state
=
{}
if
n
>
3
:
listiter
=
info
[
3
]
else
:
listiter
=
None
if
n
>
4
:
dictiter
=
info
[
4
]
else
:
dictiter
=
None
if
deep
:
if
deep
:
args
=
deepcopy
(
args
,
memo
)
args
=
deepcopy
(
args
,
memo
)
y
=
callable
(
*
args
)
y
=
callable
(
*
args
)
if
listiter
is
not
None
:
for
item
in
listiter
:
if
deep
:
item
=
deepcopy
(
item
,
memo
)
y
.
append
(
item
)
if
dictiter
is
not
None
:
for
key
,
value
in
dictiter
:
if
deep
:
key
=
deepcopy
(
key
,
memo
)
value
=
deepcopy
(
value
,
memo
)
y
[
key
]
=
value
if
state
:
if
state
:
if
deep
:
if
deep
:
state
=
deepcopy
(
state
,
memo
)
state
=
deepcopy
(
state
,
memo
)
...
...
Lib/test/test_copy.py
View file @
e311453b
...
@@ -375,6 +375,42 @@ class TestCopy(unittest.TestCase):
...
@@ -375,6 +375,42 @@ class TestCopy(unittest.TestCase):
self
.
assertEqual
(
y
,
x
)
self
.
assertEqual
(
y
,
x
)
self
.
assert_
(
y
.
foo
is
not
x
.
foo
)
self
.
assert_
(
y
.
foo
is
not
x
.
foo
)
# Additions for Python 2.3 and pickle protocol 2
def
test_reduce_4tuple
(
self
):
class
C
(
list
):
def
__reduce__
(
self
):
return
(
C
,
(),
self
.
__dict__
,
iter
(
self
))
def
__cmp__
(
self
,
other
):
return
(
cmp
(
list
(
self
),
list
(
other
))
or
cmp
(
self
.
__dict__
,
other
.
__dict__
))
x
=
C
([[
1
,
2
],
3
])
y
=
copy
.
copy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assert_
(
x
is
not
y
)
self
.
assert_
(
x
[
0
]
is
y
[
0
])
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assert_
(
x
is
not
y
)
self
.
assert_
(
x
[
0
]
is
not
y
[
0
])
def
test_reduce_5tuple
(
self
):
class
C
(
dict
):
def
__reduce__
(
self
):
return
(
C
,
(),
self
.
__dict__
,
None
,
self
.
iteritems
())
def
__cmp__
(
self
,
other
):
return
(
cmp
(
dict
(
self
),
list
(
dict
))
or
cmp
(
self
.
__dict__
,
other
.
__dict__
))
x
=
C
([(
"foo"
,
[
1
,
2
]),
(
"bar"
,
3
)])
y
=
copy
.
copy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assert_
(
x
is
not
y
)
self
.
assert_
(
x
[
"foo"
]
is
y
[
"foo"
])
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assert_
(
x
is
not
y
)
self
.
assert_
(
x
[
"foo"
]
is
not
y
[
"foo"
])
def
test_main
():
def
test_main
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestCopy
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestCopy
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment