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
1faf9025
Kaydet (Commit)
1faf9025
authored
Eki 25, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #27275: Fixed implementation of pop() and popitem() methods in
subclasses of accelerated OrderedDict.
üst
ecb90182
48325805
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
22 deletions
+69
-22
test_ordered_dict.py
Lib/test/test_ordered_dict.py
+59
-0
NEWS
Misc/NEWS
+3
-0
odictobject.c
Objects/odictobject.c
+7
-22
No files found.
Lib/test/test_ordered_dict.py
Dosyayı görüntüle @
1faf9025
...
...
@@ -775,5 +775,64 @@ class CPythonSubclassMappingTests(mapping_tests.BasicTestMappingProtocol):
self
.
assertRaises
(
KeyError
,
d
.
popitem
)
class
SimpleLRUCache
:
def
__init__
(
self
,
size
):
super
()
.
__init__
()
self
.
size
=
size
def
__getitem__
(
self
,
item
):
value
=
super
()
.
__getitem__
(
item
)
self
.
move_to_end
(
item
)
return
value
def
__setitem__
(
self
,
key
,
value
):
while
key
not
in
self
and
len
(
self
)
>=
self
.
size
:
self
.
popitem
(
last
=
False
)
super
()
.
__setitem__
(
key
,
value
)
self
.
move_to_end
(
key
)
class
SimpleLRUCacheTests
:
def
test_add_after_full
(
self
):
c
=
self
.
type2test
(
2
)
c
[
't1'
]
=
1
c
[
't2'
]
=
2
c
[
't3'
]
=
3
self
.
assertEqual
(
list
(
c
),
[
't2'
,
't3'
])
def
test_popitem
(
self
):
c
=
self
.
type2test
(
3
)
for
i
in
range
(
1
,
4
):
c
[
i
]
=
i
self
.
assertEqual
(
c
.
popitem
(
last
=
False
),
(
1
,
1
))
self
.
assertEqual
(
c
.
popitem
(
last
=
True
),
(
3
,
3
))
def
test_change_order_on_get
(
self
):
c
=
self
.
type2test
(
3
)
for
i
in
range
(
1
,
4
):
c
[
i
]
=
i
self
.
assertEqual
(
list
(
c
),
list
(
range
(
1
,
4
)))
self
.
assertEqual
(
c
[
2
],
2
)
self
.
assertEqual
(
list
(
c
),
[
1
,
3
,
2
])
class
PySimpleLRUCacheTests
(
SimpleLRUCacheTests
,
unittest
.
TestCase
):
class
type2test
(
SimpleLRUCache
,
py_coll
.
OrderedDict
):
pass
@unittest.skipUnless
(
c_coll
,
'requires the C version of the collections module'
)
class
CSimpleLRUCacheTests
(
SimpleLRUCacheTests
,
unittest
.
TestCase
):
@classmethod
def
setUpClass
(
cls
):
class
type2test
(
SimpleLRUCache
,
c_coll
.
OrderedDict
):
pass
cls
.
type2test
=
type2test
if
__name__
==
"__main__"
:
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
1faf9025
...
...
@@ -29,6 +29,9 @@ Core and Builtins
Library
-------
- Issue #27275: Fixed implementation of pop() and popitem() methods in
subclasses of accelerated OrderedDict.
- Issue #28255: calendar.TextCalendar().prmonth() no longer prints a space
at the start of new line after printing a month'
s
calendar
.
Patch
by
Xiang
Zhang
.
...
...
Objects/odictobject.c
Dosyayı görüntüle @
1faf9025
...
...
@@ -1102,28 +1102,13 @@ _odict_popkey_hash(PyObject *od, PyObject *key, PyObject *failobj,
}
/* Now delete the value from the dict. */
if
(
PyODict_CheckExact
(
od
))
{
if
(
node
!=
NULL
)
{
value
=
_PyDict_GetItem_KnownHash
(
od
,
key
,
hash
);
/* borrowed */
if
(
value
!=
NULL
)
{
Py_INCREF
(
value
);
if
(
_PyDict_DelItem_KnownHash
(
od
,
key
,
hash
)
<
0
)
{
Py_DECREF
(
value
);
return
NULL
;
}
}
}
}
else
{
int
exists
=
PySequence_Contains
(
od
,
key
);
if
(
exists
<
0
)
return
NULL
;
if
(
exists
)
{
value
=
PyObject_GetItem
(
od
,
key
);
if
(
value
!=
NULL
)
{
if
(
PyObject_DelItem
(
od
,
key
)
==
-
1
)
{
Py_CLEAR
(
value
);
}
if
(
node
!=
NULL
)
{
value
=
_PyDict_GetItem_KnownHash
(
od
,
key
,
hash
);
/* borrowed */
if
(
value
!=
NULL
)
{
Py_INCREF
(
value
);
if
(
_PyDict_DelItem_KnownHash
(
od
,
key
,
hash
)
<
0
)
{
Py_DECREF
(
value
);
return
NULL
;
}
}
}
...
...
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