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
08c70cf5
Commit
08c70cf5
authored
Mar 03, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the underlying data structure more private.
parent
b0d56afc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
Lib/collections.py
Lib/collections.py
+13
-9
No files found.
Lib/collections.py
View file @
08c70cf5
...
...
@@ -22,40 +22,44 @@ class OrderedDict(dict, MutableMapping):
def
__init__
(
self
,
*
args
,
**
kwds
):
if
len
(
args
)
>
1
:
raise
TypeError
(
'expected at most 1 arguments, got %d'
%
len
(
args
))
if
not
hasattr
(
self
,
'_keys'
):
self
.
_keys
=
[]
try
:
self
.
__keys
except
AttributeError
:
# Note the underlying data structure for this class is likely to
# change in the future. Do not rely on it or access it directly.
self
.
__keys
=
[]
self
.
update
(
*
args
,
**
kwds
)
def
clear
(
self
):
del
self
.
_keys
[:]
del
self
.
_
_
keys
[:]
dict
.
clear
(
self
)
def
__setitem__
(
self
,
key
,
value
):
if
key
not
in
self
:
self
.
_keys
.
append
(
key
)
self
.
_
_
keys
.
append
(
key
)
dict
.
__setitem__
(
self
,
key
,
value
)
def
__delitem__
(
self
,
key
):
dict
.
__delitem__
(
self
,
key
)
self
.
_keys
.
remove
(
key
)
self
.
_
_
keys
.
remove
(
key
)
def
__iter__
(
self
):
return
iter
(
self
.
_keys
)
return
iter
(
self
.
_
_
keys
)
def
__reversed__
(
self
):
return
reversed
(
self
.
_keys
)
return
reversed
(
self
.
_
_
keys
)
def
popitem
(
self
):
if
not
self
:
raise
KeyError
(
'dictionary is empty'
)
key
=
self
.
_keys
.
pop
()
key
=
self
.
_
_
keys
.
pop
()
value
=
dict
.
pop
(
self
,
key
)
return
key
,
value
def
__reduce__
(
self
):
items
=
[[
k
,
self
[
k
]]
for
k
in
self
]
inst_dict
=
vars
(
self
).
copy
()
inst_dict
.
pop
(
'_keys'
,
None
)
inst_dict
.
pop
(
'_
_
keys'
,
None
)
return
(
self
.
__class__
,
(
items
,),
inst_dict
)
setdefault
=
MutableMapping
.
setdefault
...
...
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