16
16
for Python 2.5 has been set; it will probably be released in the
17
17
autumn of 2006.
18
18
19
- % Compare with previous release in 2 - 3 sentences here.
19
+ % XXX Compare with previous release in 2 - 3 sentences here.
20
20
21
21
This article doesn't attempt to provide a complete specification of
22
22
the new features, but instead provides a convenient overview. For
23
23
full details, you should refer to the documentation for Python 2.5.
24
- % add hyperlink when the documentation becomes available online.
24
+ % XXX add hyperlink when the documentation becomes available online.
25
25
If you want to understand the complete implementation and design
26
26
rationale, refer to the PEP for a particular new feature.
27
27
28
28
29
+ % ======================================================================
30
+ \section {PEP 308: Conditional Expressions }
31
+
32
+ % XXX write this
33
+
34
+
29
35
% ======================================================================
30
36
\section {PEP 309: Partial Function Application }
31
37
32
38
The \module {functional} module is intended to contain tools for
33
- functional-style programming. Currently it only contains
34
- \class {partial} , but new functions will probably be added in future
35
- versions of Python.
39
+ functional-style programming. Currently it only contains a
40
+ \class {partial()} function , but new functions will probably be added
41
+ in future versions of Python.
36
42
37
43
For programs written in a functional style, it can be useful to
38
44
construct variants of existing functions that have some of the
@@ -59,6 +65,7 @@ \section{PEP 309: Partial Function Application}
59
65
...
60
66
61
67
server_log = functional.partial(log, subsystem='server')
68
+ server_log('Unable to open socket')
62
69
\end {verbatim }
63
70
64
71
Here's another example, from a program that uses PyGTk. Here a
@@ -91,15 +98,15 @@ \section{PEP 309: Partial Function Application}
91
98
\section {PEP 314: Metadata for Python Software Packages v1.1 }
92
99
93
100
Some simple dependency support was added to Distutils. The
94
- \function {setup()} function now has \code {requires},\code {provides},
95
- and \code {obsoletes}. When you build a source distribution using the
96
- \code {sdist} command, the dependency information will be recorded in
97
- the \file {PKG-INFO} file.
101
+ \function {setup()} function now has \code {requires}, \code {provides},
102
+ and \code {obsoletes} keyword parameters . When you build a source
103
+ distribution using the \code {sdist} command, the dependency
104
+ information will be recorded in the \file {PKG-INFO} file.
98
105
99
- Another new keyword is \code {download_url}, which should be set to a
100
- URL for the package's source code. This means it's now possible to
101
- look up an entry in the package index, determine the dependencies for
102
- a package, and download the required packages.
106
+ Another new keyword parameter is \code {download_url}, which should be
107
+ set to a URL for the package's source code. This means it's now
108
+ possible to look up an entry in the package index, determine the
109
+ dependencies for a package, and download the required packages.
103
110
104
111
% XXX put example here
105
112
@@ -112,16 +119,28 @@ \section{PEP 314: Metadata for Python Software Packages v1.1}
112
119
\end {seealso }
113
120
114
121
122
+ % ======================================================================
123
+ \section {PEP 328: Absolute and Relative Imports }
124
+
125
+ % XXX write this
126
+
127
+
128
+ % ======================================================================
129
+ \section {PEP 341: Unified try/except/finally }
130
+
131
+ % XXX write this
132
+
133
+
115
134
% ======================================================================
116
135
\section {PEP 342: New Generator Features }
117
136
118
137
As introduced in Python 2.3, generators only produce output; once a
119
- generator's code was invoked to create an iterator, there's no way to
120
- pass new parameters into the function when its execution is resumed.
121
- Hackish solutions to this include making the generator's code look at
122
- a global variable and then changing the global variable's value, or
123
- passing in some mutable object that callers then modify. Python
124
- 2.5 adds the ability to pass values \emph {into } a generator.
138
+ generator's code is invoked to create an iterator, there's no way to
139
+ pass any new information into the function when its execution is
140
+ resumed. Hackish solutions to this include making the generator's
141
+ code look at a global variable and then changing the global variable's
142
+ value, or passing in some mutable object that callers then modify.
143
+ Python 2.5 adds the ability to pass values \emph {into } a generator.
125
144
126
145
To refresh your memory of basic generators, here's a simple example:
127
146
@@ -138,7 +157,7 @@ \section{PEP 342: New Generator Features}
138
157
\keyword {yield} statement, the iterator returns the provided value and
139
158
suspends the function's execution, preserving the local variables.
140
159
Execution resumes on the following call to the iterator's
141
- \method {next()} method, picking up after the \keyword {yield}.
160
+ \method {next()} method, picking up after the \keyword {yield} statement .
142
161
143
162
In Python 2.3, \keyword {yield} was a statement; it didn't return any
144
163
value. In 2.5, \keyword {yield} is now an expression, returning a
@@ -152,17 +171,17 @@ \section{PEP 342: New Generator Features}
152
171
expression when you're doing something with the returned value, as in
153
172
the above example. The parentheses aren't always necessary, but it's
154
173
easier to always add them instead of having to remember when they're
155
- needed. The exact rules are that a \keyword {yield}-expression must
174
+ needed.\footnote { The exact rules are that a \keyword {yield}-expression must
156
175
always be parenthesized except when it occurs at the top-level
157
- expression on the right-hand side of an assignment, meaning
158
- you can to write \code {val = yield i} but \code {val = (yield i) + 12}.
159
- % XXX ending of last para makes no sense
176
+ expression on the right-hand side of an assignment, meaning you can
177
+ write \code {val = yield i} but have to use parentheses when there's an
178
+ operation, as in \code {val = (yield i) + 12}.}
160
179
161
180
Values are sent into a generator by calling its
162
181
\method {send(\var {value})} method. The generator's code is then
163
- resumed and the \keyword {yield} expression produces \var {value}.
164
- If the regular \method {next()} method is called, the \keyword {yield}
165
- returns \constant {None}.
182
+ resumed and the \keyword {yield} expression returns the specified
183
+ \var {value}. If the regular \method {next()} method is called, the
184
+ \keyword {yield} returns \constant {None}.
166
185
167
186
Here's the previous example, modified to allow changing the value of
168
187
the internal counter.
@@ -198,12 +217,13 @@ \section{PEP 342: New Generator Features}
198
217
StopIteration
199
218
\end {verbatim }
200
219
201
- Because \keyword {yield} will often be returning \constant {None},
202
- you shouldn't just use its value in expressions unless you're sure
203
- that only the \method {send()} method will be used.
220
+ Because \keyword {yield} will often be returning \constant {None}, you
221
+ should always check for this case. Don't just use its value in
222
+ expressions unless you're sure that the \method {send()} method
223
+ will be the only method used resume your generator function.
204
224
205
- There are two other new methods on generators in addition to
206
- \method {send()} :
225
+ In addition to \method {send()}, there are two other new methods on
226
+ generators :
207
227
208
228
\begin {itemize }
209
229
@@ -229,13 +249,14 @@ \section{PEP 342: New Generator Features}
229
249
230
250
The cumulative effect of these changes is to turn generators from
231
251
one-way producers of information into both producers and consumers.
252
+
232
253
Generators also become \emph {coroutines }, a more generalized form of
233
- subroutines; subroutines are entered at one point and exited at
254
+ subroutines. Subroutines are entered at one point and exited at
234
255
another point (the top of the function, and a \keyword {return
235
256
statement}), but coroutines can be entered, exited, and resumed at
236
- many different points (the \keyword {yield} statements).science term
257
+ many different points (the \keyword {yield} statements).
258
+
237
259
238
-
239
260
\begin {seealso }
240
261
241
262
\seepep {342}{Coroutines via Enhanced Generators}{PEP written by
@@ -253,6 +274,18 @@ \section{PEP 342: New Generator Features}
253
274
\end {seealso }
254
275
255
276
277
+ % ======================================================================
278
+ \section {PEP 343: The 'with' statement }
279
+
280
+ % XXX write this
281
+
282
+
283
+ % ======================================================================
284
+ \section {PEP 357: The '__index__' method }
285
+
286
+ % XXX write this
287
+
288
+
256
289
% ======================================================================
257
290
\section {Other Language Changes }
258
291
0 commit comments