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
a673b1fd
Kaydet (Commit)
a673b1fd
authored
Ara 31, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix OrderedDict.setdefault() to work for subclasses that define __missing__().
üst
ed13853e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
1 deletion
+16
-1
collections.py
Lib/collections.py
+7
-1
test_collections.py
Lib/test/test_collections.py
+6
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/collections.py
Dosyayı görüntüle @
a673b1fd
...
@@ -171,7 +171,6 @@ class OrderedDict(dict, MutableMapping):
...
@@ -171,7 +171,6 @@ class OrderedDict(dict, MutableMapping):
size
+=
sizeof
(
self
.
__root
)
*
n
# proxy objects
size
+=
sizeof
(
self
.
__root
)
*
n
# proxy objects
return
size
return
size
setdefault
=
MutableMapping
.
setdefault
update
=
MutableMapping
.
update
update
=
MutableMapping
.
update
pop
=
MutableMapping
.
pop
pop
=
MutableMapping
.
pop
keys
=
MutableMapping
.
keys
keys
=
MutableMapping
.
keys
...
@@ -179,6 +178,13 @@ class OrderedDict(dict, MutableMapping):
...
@@ -179,6 +178,13 @@ class OrderedDict(dict, MutableMapping):
items
=
MutableMapping
.
items
items
=
MutableMapping
.
items
__ne__
=
MutableMapping
.
__ne__
__ne__
=
MutableMapping
.
__ne__
def
setdefault
(
self
,
key
,
default
=
None
):
'OD.setdefault(k[,d]) -> OD.get(k,d), also set OD[k]=d if k not in OD'
if
key
in
self
:
return
self
[
key
]
self
[
key
]
=
default
return
default
@_recursive_repr
()
@_recursive_repr
()
def
__repr__
(
self
):
def
__repr__
(
self
):
'od.__repr__() <==> repr(od)'
'od.__repr__() <==> repr(od)'
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
a673b1fd
...
@@ -976,6 +976,12 @@ class TestOrderedDict(unittest.TestCase):
...
@@ -976,6 +976,12 @@ class TestOrderedDict(unittest.TestCase):
# make sure 'x' is added to the end
# make sure 'x' is added to the end
self
.
assertEqual
(
list
(
od
.
items
())[
-
1
],
(
'x'
,
10
))
self
.
assertEqual
(
list
(
od
.
items
())[
-
1
],
(
'x'
,
10
))
# make sure setdefault still works when __missing__ is defined
class
Missing
(
OrderedDict
):
def
__missing__
(
self
,
key
):
return
0
self
.
assertEqual
(
Missing
()
.
setdefault
(
5
,
9
),
9
)
def
test_reinsert
(
self
):
def
test_reinsert
(
self
):
# Given insert a, insert b, delete a, re-insert a,
# Given insert a, insert b, delete a, re-insert a,
# verify that a is now later than b.
# verify that a is now later than b.
...
...
Misc/NEWS
Dosyayı görüntüle @
a673b1fd
...
@@ -20,6 +20,9 @@ Core and Builtins
...
@@ -20,6 +20,9 @@ Core and Builtins
Library
Library
-------
-------
- Fix collections.OrderedDict.setdefault() so that it works in
subclasses that define __missing__().
- Issue 10786: unittest.TextTestRunner default stream no longer bound at
- Issue 10786: unittest.TextTestRunner default stream no longer bound at
import time. `sys.stderr` now looked up at instantiation time. Fix contributed
import time. `sys.stderr` now looked up at instantiation time. Fix contributed
by Mark Roddy.
by Mark Roddy.
...
...
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