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
35c87f2b
Kaydet (Commit)
35c87f2b
authored
Eyl 16, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 9865: add __sizeof__ to OrderedDict.
üst
234f88dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
11 deletions
+28
-11
collections.py
Lib/collections.py
+20
-11
test_collections.py
Lib/test/test_collections.py
+6
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/collections.py
Dosyayı görüntüle @
35c87f2b
...
@@ -97,17 +97,6 @@ class OrderedDict(dict, MutableMapping):
...
@@ -97,17 +97,6 @@ class OrderedDict(dict, MutableMapping):
yield
curr
.
key
yield
curr
.
key
curr
=
curr
.
prev
curr
=
curr
.
prev
def
__reduce__
(
self
):
'Return state information for pickling'
items
=
[[
k
,
self
[
k
]]
for
k
in
self
]
tmp
=
self
.
__map
,
self
.
__root
,
self
.
__hardroot
del
self
.
__map
,
self
.
__root
,
self
.
__hardroot
inst_dict
=
vars
(
self
)
.
copy
()
self
.
__map
,
self
.
__root
,
self
.
__hardroot
=
tmp
if
inst_dict
:
return
(
self
.
__class__
,
(
items
,),
inst_dict
)
return
self
.
__class__
,
(
items
,)
def
clear
(
self
):
def
clear
(
self
):
'od.clear() -> None. Remove all items from od.'
'od.clear() -> None. Remove all items from od.'
root
=
self
.
__root
root
=
self
.
__root
...
@@ -162,6 +151,26 @@ class OrderedDict(dict, MutableMapping):
...
@@ -162,6 +151,26 @@ class OrderedDict(dict, MutableMapping):
link
.
next
=
first
link
.
next
=
first
root
.
next
=
first
.
prev
=
link
root
.
next
=
first
.
prev
=
link
def
__reduce__
(
self
):
'Return state information for pickling'
items
=
[[
k
,
self
[
k
]]
for
k
in
self
]
tmp
=
self
.
__map
,
self
.
__root
,
self
.
__hardroot
del
self
.
__map
,
self
.
__root
,
self
.
__hardroot
inst_dict
=
vars
(
self
)
.
copy
()
self
.
__map
,
self
.
__root
,
self
.
__hardroot
=
tmp
if
inst_dict
:
return
(
self
.
__class__
,
(
items
,),
inst_dict
)
return
self
.
__class__
,
(
items
,)
def
__sizeof__
(
self
):
sizeof
=
_sys
.
getsizeof
n
=
len
(
self
)
+
1
# number of links including root
size
=
sizeof
(
self
.
__dict__
)
# instance dictionary
size
+=
sizeof
(
self
.
__map
)
*
2
# internal dict and inherited dict
size
+=
sizeof
(
self
.
__hardroot
)
*
n
# link objects
size
+=
sizeof
(
self
.
__root
)
*
n
# proxy objects
return
size
setdefault
=
MutableMapping
.
setdefault
setdefault
=
MutableMapping
.
setdefault
update
=
MutableMapping
.
update
update
=
MutableMapping
.
update
pop
=
MutableMapping
.
pop
pop
=
MutableMapping
.
pop
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
35c87f2b
...
@@ -994,6 +994,12 @@ class TestOrderedDict(unittest.TestCase):
...
@@ -994,6 +994,12 @@ class TestOrderedDict(unittest.TestCase):
with
self
.
assertRaises
(
KeyError
):
with
self
.
assertRaises
(
KeyError
):
od
.
move_to_end
(
'x'
)
od
.
move_to_end
(
'x'
)
def
test_sizeof
(
self
):
# Wimpy test: Just verify the reported size is larger than a regular dict
d
=
dict
(
a
=
1
)
od
=
OrderedDict
(
**
d
)
self
.
assertGreater
(
sys
.
getsizeof
(
od
),
sys
.
getsizeof
(
d
))
class
GeneralMappingTests
(
mapping_tests
.
BasicTestMappingProtocol
):
class
GeneralMappingTests
(
mapping_tests
.
BasicTestMappingProtocol
):
type2test
=
OrderedDict
type2test
=
OrderedDict
...
...
Misc/NEWS
Dosyayı görüntüle @
35c87f2b
...
@@ -52,6 +52,8 @@ Core and Builtins
...
@@ -52,6 +52,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #9865: collections.OrderedDict now has a __sizeof__ method.
- Issue #9854: The default read() implementation in io.RawIOBase now
- Issue #9854: The default read() implementation in io.RawIOBase now
handles non-blocking readinto() returning None correctly.
handles non-blocking readinto() returning None correctly.
...
...
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