Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
32062e9b
Commit
32062e9b
authored
Jan 01, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easier to extend OrderedDict without breaking it.
parent
60db4675
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
Lib/collections.py
Lib/collections.py
+2
-2
Lib/test/test_collections.py
Lib/test/test_collections.py
+8
-0
No files found.
Lib/collections.py
View file @
32062e9b
...
...
@@ -52,7 +52,7 @@ class OrderedDict(dict, MutableMapping):
self
.
__root
=
root
=
_proxy
(
self
.
__hardroot
)
root
.
prev
=
root
.
next
=
root
self
.
__map
=
{}
self
.
update
(
*
args
,
**
kwds
)
self
.
__
update
(
*
args
,
**
kwds
)
def
__setitem__
(
self
,
key
,
value
,
dict_setitem
=
dict
.
__setitem__
,
proxy
=
_proxy
,
Link
=
_Link
):
...
...
@@ -171,7 +171,7 @@ class OrderedDict(dict, MutableMapping):
size
+=
sizeof
(
self
.
__root
)
*
n
# proxy objects
return
size
update
=
MutableMapping
.
update
update
=
__update
=
MutableMapping
.
update
pop
=
MutableMapping
.
pop
keys
=
MutableMapping
.
keys
values
=
MutableMapping
.
values
...
...
Lib/test/test_collections.py
View file @
32062e9b
...
...
@@ -1012,6 +1012,14 @@ class TestOrderedDict(unittest.TestCase):
od
=
OrderedDict
(
**
d
)
self
.
assertGreater
(
sys
.
getsizeof
(
od
),
sys
.
getsizeof
(
d
))
def
test_override_update
(
self
):
# Verify that subclasses can override update() without breaking __init__()
class
MyOD
(
OrderedDict
):
def
update
(
self
,
*
args
,
**
kwds
):
raise
Exception
()
items
=
[(
'a'
,
1
),
(
'c'
,
3
),
(
'b'
,
2
)]
self
.
assertEqual
(
list
(
MyOD
(
items
).
items
()),
items
)
class
GeneralMappingTests
(
mapping_tests
.
BasicTestMappingProtocol
):
type2test
=
OrderedDict
...
...
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