Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f4e1babf
Kaydet (Commit)
f4e1babf
authored
May 19, 2019
tarafından
Bar Harel
Kaydeden (comit)
Serhiy Storchaka
May 19, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-27141: Fix collections.UserList and UserDict shallow copy. (GH-4094)
üst
c661b30f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
0 deletions
+41
-0
__init__.py
Lib/collections/__init__.py
+14
-0
test_collections.py
Lib/test/test_collections.py
+24
-0
2017-10-24-00-42-14.bpo-27141.zbAgSs.rst
...S.d/next/Library/2017-10-24-00-42-14.bpo-27141.zbAgSs.rst
+3
-0
No files found.
Lib/collections/__init__.py
Dosyayı görüntüle @
f4e1babf
...
...
@@ -1038,6 +1038,13 @@ class UserDict(_collections_abc.MutableMapping):
# Now, add the methods in dicts but not in MutableMapping
def
__repr__
(
self
):
return
repr
(
self
.
data
)
def
__copy__
(
self
):
inst
=
self
.
__class__
.
__new__
(
self
.
__class__
)
inst
.
__dict__
.
update
(
self
.
__dict__
)
# Create a copy and avoid triggering descriptors
inst
.
__dict__
[
"data"
]
=
self
.
__dict__
[
"data"
]
.
copy
()
return
inst
def
copy
(
self
):
if
self
.
__class__
is
UserDict
:
return
UserDict
(
self
.
data
.
copy
())
...
...
@@ -1050,6 +1057,7 @@ class UserDict(_collections_abc.MutableMapping):
self
.
data
=
data
c
.
update
(
self
)
return
c
@classmethod
def
fromkeys
(
cls
,
iterable
,
value
=
None
):
d
=
cls
()
...
...
@@ -1118,6 +1126,12 @@ class UserList(_collections_abc.MutableSequence):
def
__imul__
(
self
,
n
):
self
.
data
*=
n
return
self
def
__copy__
(
self
):
inst
=
self
.
__class__
.
__new__
(
self
.
__class__
)
inst
.
__dict__
.
update
(
self
.
__dict__
)
# Create a copy and avoid triggering descriptors
inst
.
__dict__
[
"data"
]
=
self
.
__dict__
[
"data"
][:]
return
inst
def
append
(
self
,
item
):
self
.
data
.
append
(
item
)
def
insert
(
self
,
i
,
item
):
self
.
data
.
insert
(
i
,
item
)
def
pop
(
self
,
i
=-
1
):
return
self
.
data
.
pop
(
i
)
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
f4e1babf
...
...
@@ -37,6 +37,20 @@ class TestUserObjects(unittest.TestCase):
b
=
b
.
__name__
,
),
)
def
_copy_test
(
self
,
obj
):
# Test internal copy
obj_copy
=
obj
.
copy
()
self
.
assertIsNot
(
obj
.
data
,
obj_copy
.
data
)
self
.
assertEqual
(
obj
.
data
,
obj_copy
.
data
)
# Test copy.copy
obj
.
test
=
[
1234
]
# Make sure instance vars are also copied.
obj_copy
=
copy
.
copy
(
obj
)
self
.
assertIsNot
(
obj
.
data
,
obj_copy
.
data
)
self
.
assertEqual
(
obj
.
data
,
obj_copy
.
data
)
self
.
assertIs
(
obj
.
test
,
obj_copy
.
test
)
def
test_str_protocol
(
self
):
self
.
_superset_test
(
UserString
,
str
)
...
...
@@ -46,6 +60,16 @@ class TestUserObjects(unittest.TestCase):
def
test_dict_protocol
(
self
):
self
.
_superset_test
(
UserDict
,
dict
)
def
test_list_copy
(
self
):
obj
=
UserList
()
obj
.
append
(
123
)
self
.
_copy_test
(
obj
)
def
test_dict_copy
(
self
):
obj
=
UserDict
()
obj
[
123
]
=
"abc"
self
.
_copy_test
(
obj
)
################################################################################
### ChainMap (helper class for configparser and the string module)
...
...
Misc/NEWS.d/next/Library/2017-10-24-00-42-14.bpo-27141.zbAgSs.rst
0 → 100644
Dosyayı görüntüle @
f4e1babf
Added a ``__copy__()`` to ``collections.UserList`` and
``collections.UserDict`` in order to correctly implement shallow copying of
the objects. Patch by Bar Harel.
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