[Python-checkins] cpython (2.7): Other minor clean-ups.

raymond.hettinger python-checkins at python.org
Sun Apr 24 21:55:41 CEST 2011


http://hg.python.org/cpython/rev/c64c41974d1f
changeset:   69540:c64c41974d1f
branch:      2.7
user:        Raymond Hettinger <python at rcn.com>
date:        Sun Apr 24 12:55:28 2011 -0700
summary:
  Other minor clean-ups.

files:
  Lib/collections.py |  23 +++++++++++++++--------
  1 files changed, 15 insertions(+), 8 deletions(-)


diff --git a/Lib/collections.py b/Lib/collections.py
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -35,9 +35,9 @@
     # Each link is stored as a list of length three:  [PREV, NEXT, KEY].
 
     def __init__(self, *args, **kwds):
-        '''Initialize an ordered dictionary.  Signature is the same as for
-        regular dictionaries, but keyword arguments are not recommended
-        because their insertion order is arbitrary.
+        '''Initialize an ordered dictionary.  The signature is the same as
+        regular dictionaries, but keyword arguments are not recommended because
+        their insertion order is arbitrary.
 
         '''
         if len(args) > 1:
@@ -69,18 +69,20 @@
         link_prev[NEXT] = link_next
         link_next[PREV] = link_prev
 
-    def __iter__(self, NEXT=1, KEY=2):
+    def __iter__(self):
         'od.__iter__() <==> iter(od)'
         # Traverse the linked list in order.
+        NEXT, KEY = 1, 2
         root = self.__root
         curr = root[NEXT]
         while curr is not root:
             yield curr[KEY]
             curr = curr[NEXT]
 
-    def __reversed__(self, PREV=0, KEY=2):
+    def __reversed__(self):
         'od.__reversed__() <==> reversed(od)'
         # Traverse the linked list in reverse order.
+        PREV, KEY = 0, 2
         root = self.__root
         curr = root[PREV]
         while curr is not root:
@@ -120,7 +122,7 @@
             yield self[k]
 
     def iteritems(self):
-        'od.iteritems -> an iterator over the (key, value) items in od'
+        'od.iteritems -> an iterator over the (key, value) pairs in od'
         for k in self:
             yield (k, self[k])
 
@@ -131,6 +133,11 @@
     __marker = object()
 
     def pop(self, key, default=__marker):
+        '''od.pop(k[,d]) -> v, remove specified key and return the corresponding
+        value.  If key is not found, d is returned if given, otherwise KeyError
+        is raised.
+
+        '''
         if key in self:
             result = self[key]
             del self[key]
@@ -186,8 +193,8 @@
 
     @classmethod
     def fromkeys(cls, iterable, value=None):
-        '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
-        and values equal to v (which defaults to None).
+        '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
+        If not specified, the value defaults to None.
 
         '''
         self = cls()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list