Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d62798

Browse files
committed
Merge
2 parents 5bb9a8f + b9b281b commit 2d62798

1 file changed

Lines changed: 67 additions & 5 deletions

File tree

Doc/whatsnew/3.3.rst

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
This article explains the new features in Python 3.3, compared to 3.2.
5050

5151

52+
.. pep-3118-update:
53+
5254
PEP 3118: New memoryview implementation and buffer protocol documentation
5355
=========================================================================
5456

@@ -85,7 +87,9 @@ Features
8587
* Multi-dimensional comparisons are supported for any array type.
8688

8789
* All array types are hashable if the exporting object is hashable
88-
and the view is read-only.
90+
and the view is read-only. (Contributed by Antoine Pitrou in
91+
:issue:`13411`)
92+
8993

9094
* Arbitrary slicing of any 1-D arrays type is supported. For example, it
9195
is now possible to reverse a memoryview in O(1) by using a negative step.
@@ -258,9 +262,56 @@ part of its operations to another generator. This allows a section of code
258262
containing 'yield' to be factored out and placed in another generator.
259263
Additionally, the subgenerator is allowed to return with a value, and the
260264
value is made available to the delegating generator.
265+
261266
While designed primarily for use in delegating to a subgenerator, the ``yield
262267
from`` expression actually allows delegation to arbitrary subiterators.
263268

269+
For simple iterators, ``yield from iterable`` is essentially just a shortened
270+
form of ``for item in iterable: yield item``::
271+
272+
>>> def g(x):
273+
... yield from range(x, 0, -1)
274+
... yield from range(x)
275+
...
276+
>>> list(g(5))
277+
[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]
278+
279+
However, unlike an ordinary loop, ``yield from`` allows subgenerators to
280+
receive sent and thrown values directly from the calling scope, and
281+
return a final value to the outer generator::
282+
283+
>>> def accumulate(start=0):
284+
... tally = start
285+
... while 1:
286+
... next = yield
287+
... if next is None:
288+
... return tally
289+
... tally += next
290+
...
291+
>>> def gather_tallies(tallies, start=0):
292+
... while 1:
293+
... tally = yield from accumulate()
294+
... tallies.append(tally)
295+
...
296+
>>> tallies = []
297+
>>> acc = gather_tallies(tallies)
298+
>>> next(acc) # Ensure the accumulator is ready to accept values
299+
>>> for i in range(10):
300+
... acc.send(i)
301+
...
302+
>>> acc.send(None) # Finish the first tally
303+
>>> for i in range(5):
304+
... acc.send(i)
305+
...
306+
>>> acc.send(None) # Finish the second tally
307+
>>> tallies
308+
[45, 10]
309+
310+
The main principle driving this change is to allow even generators that are
311+
designed to be used with the ``send`` and ``throw`` methods to be split into
312+
multiple subgenerators as easily as a single large function can be split into
313+
multiple subfunctions.
314+
264315
(Implementation by Greg Ewing, integrated into 3.3 by Renaud Blanch, Ryan
265316
Kelly and Nick Coghlan, documentation by Zbigniew Jędrzejewski-Szmek and
266317
Nick Coghlan)
@@ -327,6 +378,21 @@ suppressed valuable underlying details)::
327378
KeyError('x',)
328379

329380

381+
PEP 414: Explicit Unicode literals
382+
======================================
383+
384+
:pep:`414` - Explicit Unicode literals
385+
PEP written by Armin Ronacher.
386+
387+
To ease the transition from Python 2 for Unicode aware Python applications
388+
that make heavy use of Unicode literals, Python 3.3 once again supports the
389+
"``u``" prefix for string literals. This prefix has no semantic significance
390+
in Python 3, it is provided solely to reduce the number of purely mechanical
391+
changes in migrating to Python 3, making it easier for developers to focus on
392+
the more significant semantic changes (such as the stricter default
393+
separation of binary and text data).
394+
395+
330396
PEP 3155: Qualified name for classes and functions
331397
==================================================
332398

@@ -408,10 +474,6 @@ Some smaller changes made to the core Python language are:
408474

409475
(:issue:`12170`)
410476

411-
* Memoryview objects are now hashable when the underlying object is hashable.
412-
413-
(Contributed by Antoine Pitrou in :issue:`13411`)
414-
415477

416478
New and Improved Modules
417479
========================

0 commit comments

Comments
 (0)