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
345c49b1
Kaydet (Commit)
345c49b1
authored
Ock 01, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix OrderedDic.pop() to work for subclasses that define __missing__().
üst
32062e9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
collections.py
Lib/collections.py
+12
-2
test_collections.py
Lib/test/test_collections.py
+15
-0
No files found.
Lib/collections.py
Dosyayı görüntüle @
345c49b1
...
@@ -22,7 +22,7 @@ from reprlib import recursive_repr as _recursive_repr
...
@@ -22,7 +22,7 @@ from reprlib import recursive_repr as _recursive_repr
class
_Link
(
object
):
class
_Link
(
object
):
__slots__
=
'prev'
,
'next'
,
'key'
,
'__weakref__'
__slots__
=
'prev'
,
'next'
,
'key'
,
'__weakref__'
class
OrderedDict
(
dict
,
MutableMapping
):
class
OrderedDict
(
dict
):
'Dictionary that remembers insertion order'
'Dictionary that remembers insertion order'
# An inherited dict maps keys to values.
# An inherited dict maps keys to values.
# The inherited dict provides __getitem__, __len__, __contains__, and get.
# The inherited dict provides __getitem__, __len__, __contains__, and get.
...
@@ -172,12 +172,22 @@ class OrderedDict(dict, MutableMapping):
...
@@ -172,12 +172,22 @@ class OrderedDict(dict, MutableMapping):
return
size
return
size
update
=
__update
=
MutableMapping
.
update
update
=
__update
=
MutableMapping
.
update
pop
=
MutableMapping
.
pop
keys
=
MutableMapping
.
keys
keys
=
MutableMapping
.
keys
values
=
MutableMapping
.
values
values
=
MutableMapping
.
values
items
=
MutableMapping
.
items
items
=
MutableMapping
.
items
__ne__
=
MutableMapping
.
__ne__
__ne__
=
MutableMapping
.
__ne__
__marker
=
object
()
def
pop
(
self
,
key
,
default
=
__marker
):
if
key
in
self
:
result
=
self
[
key
]
del
self
[
key
]
return
result
if
default
is
self
.
__marker
:
raise
KeyError
(
key
)
return
default
def
setdefault
(
self
,
key
,
default
=
None
):
def
setdefault
(
self
,
key
,
default
=
None
):
'OD.setdefault(k[,d]) -> OD.get(k,d), also set OD[k]=d if k not in OD'
'OD.setdefault(k[,d]) -> OD.get(k,d), also set OD[k]=d if k not in OD'
if
key
in
self
:
if
key
in
self
:
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
345c49b1
...
@@ -834,6 +834,10 @@ class TestOrderedDict(unittest.TestCase):
...
@@ -834,6 +834,10 @@ class TestOrderedDict(unittest.TestCase):
self
.
assertEqual
(
list
(
d
.
items
()),
self
.
assertEqual
(
list
(
d
.
items
()),
[(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
),
(
'g'
,
7
)])
[(
'a'
,
1
),
(
'b'
,
2
),
(
'c'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
),
(
'g'
,
7
)])
def
test_abc
(
self
):
self
.
assertIsInstance
(
OrderedDict
(),
MutableMapping
)
self
.
assertTrue
(
issubclass
(
OrderedDict
,
MutableMapping
))
def
test_clear
(
self
):
def
test_clear
(
self
):
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
shuffle
(
pairs
)
shuffle
(
pairs
)
...
@@ -892,6 +896,17 @@ class TestOrderedDict(unittest.TestCase):
...
@@ -892,6 +896,17 @@ class TestOrderedDict(unittest.TestCase):
self
.
assertEqual
(
len
(
od
),
0
)
self
.
assertEqual
(
len
(
od
),
0
)
self
.
assertEqual
(
od
.
pop
(
k
,
12345
),
12345
)
self
.
assertEqual
(
od
.
pop
(
k
,
12345
),
12345
)
# make sure pop still works when __missing__ is defined
class
Missing
(
OrderedDict
):
def
__missing__
(
self
,
key
):
return
0
m
=
Missing
(
a
=
1
)
self
.
assertEqual
(
m
.
pop
(
'b'
,
5
),
5
)
self
.
assertEqual
(
m
.
pop
(
'a'
,
6
),
1
)
self
.
assertEqual
(
m
.
pop
(
'a'
,
6
),
6
)
with
self
.
assertRaises
(
KeyError
):
m
.
pop
(
'a'
)
def
test_equality
(
self
):
def
test_equality
(
self
):
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
shuffle
(
pairs
)
shuffle
(
pairs
)
...
...
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