PEP 308 is final. A great many thanks go to Thomas Wouters!

This commit is contained in:
Guido van Rossum 2006-02-27 16:55:05 +00:00
parent 3e2085f82e
commit df7a33afb0
2 changed files with 15 additions and 9 deletions

View File

@ -65,7 +65,6 @@ Index by Category
Accepted PEPs (accepted; may not be implemented yet)
SA 308 Conditional Expressions GvR, Hettinger
SA 328 Imports: Multi-Line and Absolute/Relative Aahz
SA 343 The "with" Statement GvR, Coghlan
SA 352 Required Superclass for Exceptions GvR, Cannon
@ -158,6 +157,7 @@ Index by Category
SF 301 Package Index and Metadata for Distutils Jones
SF 305 CSV File API Montanaro, et al
SF 307 Extensions to the pickle protocol GvR, Peters
SF 308 Conditional Expressions GvR, Hettinger
SF 309 Partial Function Application Harris
SF 311 Simplified GIL Acquisition for Extensions Hammond
SF 318 Decorators for Functions and Methods Smith, et al
@ -361,7 +361,7 @@ Numerical Index
SF 305 CSV File API Montanaro, et al
I 306 How to Change Python's Grammar Hudson
SF 307 Extensions to the pickle protocol GvR, Peters
SA 308 Conditional Expressions GvR, Hettinger
SF 308 Conditional Expressions GvR, Hettinger
SF 309 Partial Function Application Harris
SR 310 Reliable Acquisition/Release Pairs Hudson, Moore
SF 311 Simplified GIL Acquisition for Extensions Hammond

View File

@ -3,7 +3,7 @@ Title: Conditional Expressions
Version: $Revision$
Last-Modified: $Date$
Author: Guido van Rossum, Raymond D. Hettinger
Status: Accepted
Status: Final
Type: Standards Track
Content-Type: text/plain
Created: 7-Feb-2003
@ -37,7 +37,7 @@ Adding a conditional expression
...
gen_for: 'for' exprlist 'in' or_test [gen_iter]
The new syntax introduces a minor syntactical backwards
The new syntax nearly introduced a minor syntactical backwards
incompatibility. In previous Python versions, the following is
legal:
@ -46,8 +46,8 @@ Adding a conditional expression
(I.e. a list comprehension where the sequence following 'in' is an
unparenthesized series of lambdas -- or just one lambda, even.)
In Python 2.5, the series of lambdas will have to be
parenthesized:
In Python 3.0, the series of lambdas will have to be
parenthesized, e.g.:
[f for f in (lambda x: x, lambda x: x**2) if f(1) == 1]
@ -56,9 +56,15 @@ Adding a conditional expression
followed by an 'if' keyword that binds less tightly still (for
details, consider the grammar changes shown above).
Given that this is a rather odd corner of the syntax the BDFL does
not believe this backwards incompatibility requires us to use a
future statement to enable the new syntax.
However, in Python 2.5, a slightly different grammar is used that
is more backwards compatible, but constrains the grammar of a
lambda used in this position by forbidding the lambda's body to
contain an unparenthesized condition expression. Examples:
[f for f in (1, lambda x: x if x >= 0 else -1)] # OK
[f for f in 1, (lambda x: x if x >= 0 else -1)] # OK
[f for f in 1, lambda x: (x if x >= 0 else -1)] # OK
[f for f in 1, lambda x: x if x >= 0 else -1] # INVALID
References