Commit 90269246 authored by Yury Selivanov's avatar Yury Selivanov

Merge 3.5

parents c545f1ce 79cf1b04
...@@ -111,7 +111,7 @@ CPython implementation improvements: ...@@ -111,7 +111,7 @@ CPython implementation improvements:
Significantly Improved Library Modules: Significantly Improved Library Modules:
* :class:`collections.OrderedDict` is now implemented in C, which makes it * :class:`collections.OrderedDict` is now implemented in C, which makes it
4 to 100 times faster. Contributed by Eric Snow in :issue:`16991`. 4 to 100 times faster. (Contributed by Eric Snow in :issue:`16991`.)
* You may now pass bytes to the :mod:`tempfile` module's APIs and it will * You may now pass bytes to the :mod:`tempfile` module's APIs and it will
return the temporary pathname as :class:`bytes` instead of :class:`str`. return the temporary pathname as :class:`bytes` instead of :class:`str`.
...@@ -213,34 +213,33 @@ An example of a simple HTTP client written using the new syntax:: ...@@ -213,34 +213,33 @@ An example of a simple HTTP client written using the new syntax::
Similarly to asynchronous iteration, there is a new syntax for asynchronous Similarly to asynchronous iteration, there is a new syntax for asynchronous
context managers:: context managers. The following script::
>>> import asyncio import asyncio
>>> async def coro1(lock):
... print('coro1: waiting for lock') async def coro(name, lock):
... async with lock: print('coro {}: waiting for lock'.format(name))
... print('coro1: holding the lock') async with lock:
... await asyncio.sleep(1) print('coro {}: holding the lock'.format(name))
... print('coro1: releasing the lock') await asyncio.sleep(1)
... print('coro {}: releasing the lock'.format(name))
>>> async def coro2(lock):
... print('coro2: waiting for lock') loop = asyncio.get_event_loop()
... async with lock: lock = asyncio.Lock()
... print('coro2: holding the lock') coros = asyncio.gather(coro(1, lock), coro(2, lock))
... await asyncio.sleep(1) try:
... print('coro2: releasing the lock') loop.run_until_complete(coros)
... finally:
>>> loop = asyncio.get_event_loop() loop.close()
>>> lock = asyncio.Lock()
>>> coros = asyncio.gather(coro1(lock), coro2(lock), loop=loop) will print::
>>> loop.run_until_complete(coros)
coro1: waiting for lock coro 2: waiting for lock
coro1: holding the lock coro 2: holding the lock
coro2: waiting for lock coro 1: waiting for lock
coro1: releasing the lock coro 2: releasing the lock
coro2: holding the lock coro 1: holding the lock
coro2: releasing the lock coro 1: releasing the lock
>>> loop.close()
Note that both :keyword:`async for` and :keyword:`async with` can only Note that both :keyword:`async for` and :keyword:`async with` can only
be used inside a coroutine function declared with :keyword:`async def`. be used inside a coroutine function declared with :keyword:`async def`.
...@@ -325,10 +324,13 @@ unpackings:: ...@@ -325,10 +324,13 @@ unpackings::
>>> *range(4), 4 >>> *range(4), 4
(0, 1, 2, 3, 4) (0, 1, 2, 3, 4)
>>> [*range(4), 4] >>> [*range(4), 4]
[0, 1, 2, 3, 4] [0, 1, 2, 3, 4]
>>> {*range(4), 4, *(5, 6, 7)} >>> {*range(4), 4, *(5, 6, 7)}
{0, 1, 2, 3, 4, 5, 6, 7} {0, 1, 2, 3, 4, 5, 6, 7}
>>> {'x': 1, **{'y': 2}} >>> {'x': 1, **{'y': 2}}
{'x': 1, 'y': 2} {'x': 1, 'y': 2}
...@@ -352,6 +354,7 @@ Examples:: ...@@ -352,6 +354,7 @@ Examples::
>>> b'Hello %s!' % b'World' >>> b'Hello %s!' % b'World'
b'Hello World!' b'Hello World!'
>>> b'x=%i y=%f' % (1, 2.5) >>> b'x=%i y=%f' % (1, 2.5)
b'x=1 y=2.500000' b'x=1 y=2.500000'
...@@ -362,6 +365,7 @@ Unicode is not allowed for ``%s``, but it is accepted by ``%a`` (equivalent of ...@@ -362,6 +365,7 @@ Unicode is not allowed for ``%s``, but it is accepted by ``%a`` (equivalent of
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <module>
TypeError: %b requires bytes, or an object that implements __bytes__, not 'str' TypeError: %b requires bytes, or an object that implements __bytes__, not 'str'
>>> b'price: %a' % '10€' >>> b'price: %a' % '10€'
b"price: '10\\u20ac'" b"price: '10\\u20ac'"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment