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
3941a8fe
Commit
3941a8fe
authored
Sep 04, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1100562: Fix deep-copying of objects derived from the list and dict types.
Patch by Michele Orrù and Björn Lindqvist.
parent
e5a91015
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
11 deletions
+46
-11
Lib/copy.py
Lib/copy.py
+23
-11
Lib/test/test_copy.py
Lib/test/test_copy.py
+20
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/copy.py
View file @
3941a8fe
...
...
@@ -283,17 +283,7 @@ def _reconstruct(x, info, deep, memo=None):
args
=
deepcopy
(
args
,
memo
)
y
=
callable
(
*
args
)
memo
[
id
(
x
)]
=
y
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
deep
:
state
=
deepcopy
(
state
,
memo
)
...
...
@@ -309,6 +299,18 @@ def _reconstruct(x, info, deep, memo=None):
if
slotstate
is
not
None
:
for
key
,
value
in
slotstate
.
items
():
setattr
(
y
,
key
,
value
)
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
return
y
del
d
...
...
@@ -370,6 +372,16 @@ def _test():
print
(
map
(
reprlib
.
repr
,
l1
))
print
(
map
(
reprlib
.
repr
,
l2
))
print
(
map
(
reprlib
.
repr
,
l3
))
class
odict
(
dict
):
def
__init__
(
self
,
d
=
{}):
self
.
a
=
99
dict
.
__init__
(
self
,
d
)
def
__setitem__
(
self
,
k
,
i
):
dict
.
__setitem__
(
self
,
k
,
i
)
self
.
a
o
=
odict
({
"A"
:
"B"
})
x
=
deepcopy
(
o
)
print
(
o
,
x
)
if
__name__
==
'__main__'
:
_test
()
Lib/test/test_copy.py
View file @
3941a8fe
...
...
@@ -532,6 +532,26 @@ class TestCopy(unittest.TestCase):
self
.
assertEqual
(
x
.
foo
,
y
.
foo
)
self
.
assertTrue
(
x
.
foo
is
not
y
.
foo
)
def
test_deepcopy_dict_subclass
(
self
):
class
C
(
dict
):
def
__init__
(
self
,
d
=
None
):
if
not
d
:
d
=
{}
self
.
_keys
=
list
(
d
.
keys
())
super
().
__init__
(
d
)
def
__setitem__
(
self
,
key
,
item
):
super
().
__setitem__
(
key
,
item
)
if
key
not
in
self
.
_keys
:
self
.
_keys
.
append
(
key
)
x
=
C
(
d
=
{
'foo'
:
0
})
y
=
copy
.
deepcopy
(
x
)
self
.
assertEqual
(
x
,
y
)
self
.
assertEqual
(
x
.
_keys
,
y
.
_keys
)
self
.
assertTrue
(
x
is
not
y
)
x
[
'bar'
]
=
1
self
.
assertNotEqual
(
x
,
y
)
self
.
assertNotEqual
(
x
.
_keys
,
y
.
_keys
)
def
test_copy_list_subclass
(
self
):
class
C
(
list
):
pass
...
...
Misc/NEWS
View file @
3941a8fe
...
...
@@ -158,6 +158,9 @@ Extensions
Library
-------
- Issue #1100562: Fix deep-copying of objects derived from the list and
dict types. Patch by Michele Orrù and Björn Lindqvist.
- Issue #9753: Fixed socket.dup, which did not always work correctly
on Windows.
...
...
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