[Python-checkins] peps: PEP 274 has been updated to reflect current reality.

barry.warsaw python-checkins at python.org
Mon Apr 9 16:42:21 CEST 2012


http://hg.python.org/peps/rev/fc28ffc78aca
changeset:   4210:fc28ffc78aca
user:        Barry Warsaw <barry at python.org>
date:        Mon Apr 09 10:42:15 2012 -0400
summary:
  PEP 274 has been updated to reflect current reality.

files:
  pep-0274.txt |  62 +++++++++++++--------------------------
  1 files changed, 21 insertions(+), 41 deletions(-)


diff --git a/pep-0274.txt b/pep-0274.txt
--- a/pep-0274.txt
+++ b/pep-0274.txt
@@ -2,11 +2,11 @@
 Title: Dict Comprehensions
 Version: $Revision$
 Last-Modified: $Date$
-Author: barry at python.org (Barry Warsaw)
-Status: Withdrawn
+Author: Barry Warsaw <barry at python.org>
+Status: Accepted
 Type: Standards Track
 Created: 25-Oct-2001
-Python-Version: 2.3
+Python-Version: 2.7, 3.0 (originally 2.3)
 Post-History: 29-Oct-2001
 
 
@@ -19,13 +19,20 @@
     very similar to list comprehensions, except that they produce
     Python dictionary objects instead of list objects.
 
+
 Resolution
 
-    This PEP is withdrawn.  Substantially all of its benefits were
-    subsumed by generator expressions coupled with the dict() constructor.
+    This PEP was originally written for inclusion in Python 2.3.  It
+    was withdrawn after observation that substantially all of its
+    benefits were subsumed by generator expressions coupled with the
+    dict() constructor.
 
-    However, Python 3.0 introduces this exact feature, as well as the
-    closely related set comprehensions.
+    However, Python 2.7 and 3.0 introduces this exact feature, as well
+    as the closely related set comprehensions.  On 2012-04-09, the PEP
+    was changed to reflect this reality by updating its Status to
+    Accepted, and updating the Python-Version field.  The Open
+    Questions section was also removed since these have been long
+    resolved by the current implementation.
 
 
 Proposed Solution
@@ -33,10 +40,9 @@
     Dict comprehensions are just like list comprehensions, except that
     you group the expression using curly braces instead of square
     braces.  Also, the left part before the `for' keyword expresses
-    both a key and a value, separated by a colon.  (There is an
-    optional part of this PEP that allows you to use a shortcut to
-    express just the value.)  The notation is specifically designed to
-    remind you of list comprehensions as applied to dictionaries.
+    both a key and a value, separated by a colon.  The notation is
+    specifically designed to remind you of list comprehensions as
+    applied to dictionaries.
 
 
 Rationale
@@ -65,7 +71,7 @@
 
     The semantics of dict comprehensions can actually be demonstrated
     in stock Python 2.2, by passing a list comprehension to the
-    builtin dictionary constructor:
+    built-in dictionary constructor:
 
     >>> dict([(i, chr(65+i)) for i in range(4)])
 
@@ -73,7 +79,7 @@
 
     >>> {i : chr(65+i) for i in range(4)}
 
-    The dictionary constructor approach has two dictinct disadvantages
+    The dictionary constructor approach has two distinct disadvantages
     from the proposed syntax though.  First, it isn't as legible as a
     dict comprehension.  Second, it forces the programmer to create an
     in-core list object first, which could be expensive.
@@ -104,36 +110,10 @@
          2, 3): 5}
 
 
-Open Issues
-
-    - There is one further shortcut we could adopt.  Suppose we wanted
-      to create a set of items, such as in the "list_of_email_addrs"
-      example above.  Here, we're simply taking the target of the for
-      loop and turning that into the key for the dict comprehension.
-      The assertion is that this would be a common idiom, so the
-      shortcut below allows for an easy spelling of it, by allow us to
-      omit the "key :" part of the left hand clause:
-
-      >>> print {1 for x in list_of_email_addrs}
-      {'barry at zope.com'   : 1, 'barry at python.org' : 1, 'guido at python.org' : 1}
-
-      Or say we wanted to map email addresses to the MX record handling
-      their mail:
-
-      >>> print {mx_for_addr(x) for x in list_of_email_addrs}
-      {'barry at zope.com'   : 'mail.zope.com',
-       'barry at python.org' : 'mail.python.org,
-       'guido at python.org' : 'mail.python.org,
-       }
-
-      Questions: what about nested loops?  Where does the key come
-      from?  The shortcut probably doesn't save much typing, and comes
-      at the expense of legibility, so it's of dubious value.
-
-
 Implementation
 
-    TBD
+    All implementation details were resolved in the Python 2.7 and 3.0
+    time-frame. 
 
 
 References

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


More information about the Python-checkins mailing list