Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5db3e01

Browse files
committed
Minor clean-ups to docstrings, comments, and var names.
1 parent 7fdd0fe commit 5db3e01

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

Lib/collections.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ class OrderedDict(dict):
2727
# An inherited dict maps keys to values.
2828
# The inherited dict provides __getitem__, __len__, __contains__, and get.
2929
# The remaining methods are order-aware.
30-
# Big-O running times for all methods are the same as for regular dictionaries.
30+
# Big-O running times for all methods are the same as regular dictionaries.
3131

32-
# The internal self.__map dictionary maps keys to links in a doubly linked list.
32+
# The internal self.__map dict maps keys to links in a doubly linked list.
3333
# The circular doubly linked list starts and ends with a sentinel element.
3434
# The sentinel element never gets deleted (this simplifies the algorithm).
35-
# The sentinel is stored in self.__hardroot with a weakref proxy in self.__root.
35+
# The sentinel is in self.__hardroot with a weakref proxy in self.__root.
3636
# The prev/next links are weakref proxies (to prevent circular references).
3737
# Individual links are kept alive by the hard reference in self.__map.
3838
# Those hard references disappear when a key is deleted from an OrderedDict.
3939

4040
def __init__(self, *args, **kwds):
41-
'''Initialize an ordered dictionary. Signature is the same as for
42-
regular dictionaries, but keyword arguments are not recommended
43-
because their insertion order is arbitrary.
41+
'''Initialize an ordered dictionary. The signature is the same as
42+
regular dictionaries, but keyword arguments are not recommended because
43+
their insertion order is arbitrary.
4444
4545
'''
4646
if len(args) > 1:
@@ -57,8 +57,8 @@ def __init__(self, *args, **kwds):
5757
def __setitem__(self, key, value,
5858
dict_setitem=dict.__setitem__, proxy=_proxy, Link=_Link):
5959
'od.__setitem__(i, y) <==> od[i]=y'
60-
# Setting a new item creates a new link which goes at the end of the linked
61-
# list, and the inherited dictionary is updated with the new key/value pair.
60+
# Setting a new item creates a new link at the end of the linked list,
61+
# and the inherited dictionary is updated with the new key/value pair.
6262
if key not in self:
6363
self.__map[key] = link = Link()
6464
root = self.__root
@@ -70,8 +70,8 @@ def __setitem__(self, key, value,
7070

7171
def __delitem__(self, key, dict_delitem=dict.__delitem__):
7272
'od.__delitem__(y) <==> del od[y]'
73-
# Deleting an existing item uses self.__map to find the link which is
74-
# then removed by updating the links in the predecessor and successor nodes.
73+
# Deleting an existing item uses self.__map to find the link which gets
74+
# removed by updating the links in the predecessor and successor nodes.
7575
dict_delitem(self, key)
7676
link = self.__map.pop(key)
7777
link_prev = link.prev
@@ -169,6 +169,11 @@ def __sizeof__(self):
169169
__marker = object()
170170

171171
def pop(self, key, default=__marker):
172+
'''od.pop(k[,d]) -> v, remove specified key and return the corresponding
173+
value. If key is not found, d is returned if given, otherwise KeyError
174+
is raised.
175+
176+
'''
172177
if key in self:
173178
result = self[key]
174179
del self[key]
@@ -178,7 +183,7 @@ def pop(self, key, default=__marker):
178183
return default
179184

180185
def setdefault(self, key, default=None):
181-
'OD.setdefault(k[,d]) -> OD.get(k,d), also set OD[k]=d if k not in OD'
186+
'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
182187
if key in self:
183188
return self[key]
184189
self[key] = default
@@ -207,14 +212,14 @@ def copy(self):
207212

208213
@classmethod
209214
def fromkeys(cls, iterable, value=None):
210-
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
211-
and values equal to v (which defaults to None).
215+
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
216+
If not specified, the value defaults to None.
212217
213218
'''
214-
d = cls()
219+
self = cls()
215220
for key in iterable:
216-
d[key] = value
217-
return d
221+
self[key] = value
222+
return self
218223

219224
def __eq__(self, other):
220225
'''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive

0 commit comments

Comments
 (0)