[Python-checkins] r64306 - peps/trunk/pep-0372.txt

georg.brandl python-checkins at python.org
Mon Jun 16 12:15:48 CEST 2008


Author: georg.brandl
Date: Mon Jun 16 12:15:48 2008
New Revision: 64306
Log:
Updates and fixes from Armin.
Modified:
 peps/trunk/pep-0372.txt
Modified: peps/trunk/pep-0372.txt
==============================================================================
--- peps/trunk/pep-0372.txt	(original)
+++ peps/trunk/pep-0372.txt	Mon Jun 16 12:15:48 2008
@@ -31,8 +31,8 @@
 Some dynamic programming languages like PHP and Ruby 1.9 guarantee a
 certain order on iteration. In those languages, and existing Python
 ordered-dict implementations, the ordering of items is defined by the
-time of insertion of the key. New keys are appended at the end, keys
-that are overwritten and not moved.
+time of insertion of the key. New keys are appended at the end, but
+keys that are overwritten are not moved to the end.
 
 The following example shows the behavior for simple assignments:
 
@@ -67,6 +67,11 @@
 Django currently uses an ugly hack to restore the ordering of
 members in database models.
 
+- The RawConfigParser class accepts a ``dict_type`` argument that
+ allows an application to set the type of dictionary used internally.
+ The motivation for this addition was expressly to allow users to
+ provide an ordered dictionary. [1]_
+ 
 - Code ported from other programming languages such as PHP often
 depends on a ordered dict. Having an implementation of an
 ordering-preserving dictionary in the standard library could ease
@@ -106,34 +111,37 @@
 
 New methods not available on dict:
 
- ``odict.byindex(index)``
+``odict.byindex(index)``
 
- Index-based lookup is supported by ``byindex()`` which returns
- the key/value pair for an index, that is, the "position" of a
- key in the ordered dict. 0 is the first key/value pair, -1
- the last.
+ Returns the key/value pair for an index, that is, the "position" of a key in
+ the ordered dict. 0 is the first key/value pair, -1 the last.
 
- >>> d.byindex(2)
- ('foo', 'bar')
+ >>> d.byindex(2)
+ ('foo', 'bar')
 
- ``odict.sort(cmp=None, key=None, reverse=False)``
+ If there is no key for index an `IndexError` is raised.
 
- Sorts the odict in place by cmp or key. This works exactly
- like ``list.sort()``, but the comparison functions are passed
- a key/value tuple, not only the value.
+``odict.index(key)``
 
- >>> d = odict([(42, 1), (1, 4), (23, 7)])
- >>> d.sort()
- >>> d
- collections.odict([(1, 4), (23, 7), (42, 1)])
+ Returns the index of a key. If the key does not exist, a `ValueError` is
+ raised.
 
- ``odict.reverse()``
+``odict.sort(cmp=None, key=None, reverse=False)``
 
- Reverses the odict in place.
+ Sorts the odict in place by cmp or key. This works exactly like
+ ``list.sort()``, but the comparison functions are passed a key/value tuple,
+ not only the value.
 
- ``odict.__reverse__()``
+ >>> d = odict([(42, 1), (1, 4), (23, 7)]) d.sort() d
+ collections.odict([(1, 4), (23, 7), (42, 1)])
 
- Supports reverse iteration by key.
+``odict.reverse()``
+
+ Reverses the odict in place.
+
+``odict.__reverse__()``
+
+ Supports reverse iteration by key.
 
 
 Questions and Answers
@@ -145,10 +153,10 @@
 consistent with existing implementations and allows subclasses to
 change the behavior easily::
 
- class movingcollections.odict):
+ class moving_odict(collections.odict):
 def __setitem__(self, key, value):
 self.pop(key, None)
- odict.__setitem__(self, key, value)
+ collections.odict.__setitem__(self, key, value)
 
 What happens if keys appear multiple times in the list passed to the
 constructor?
@@ -217,6 +225,12 @@
 of the source file.
 
 
+References
+==========
+
+.. [1] http://bugs.python.org/issue1371075
+
+
 Copyright
 =========
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /