pep-567: More fixes (#505)

This commit is contained in:
Yury Selivanov 2017-12-12 21:39:08 -05:00 committed by GitHub
parent c1f434c437
commit 4a8143fc16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -78,16 +78,15 @@ is accessed via ``contextvars.get_context()`` function.
Manipulation of the current ``Context`` is the responsibility of the Manipulation of the current ``Context`` is the responsibility of the
task framework, e.g. asyncio. task framework, e.g. asyncio.
A ``Context`` is conceptually a mapping, implemented using an A ``Context`` is conceptually a read-only mapping, implemented using
immutable dictionary. The ``ContextVar.get()`` method does a an immutable dictionary. The ``ContextVar.get()`` method does a
lookup in the current ``Context`` with ``self`` as a key, raising a lookup in the current ``Context`` with ``self`` as a key, raising a
``LookupError`` or returning a default value specified in ``LookupError`` or returning a default value specified in
the constructor. the constructor.
The ``ContextVar.set(value)`` method clones the current ``Context``, The ``ContextVar.set(value)`` method clones the current ``Context``,
assigns the ``value`` to it with ``self`` as a key, and sets the assigns the ``value`` to it with ``self`` as a key, and sets the
new ``Context`` as a new current. Because ``Context`` uses an new ``Context`` as a new current.
immutable dictionary, cloning it is O(1).
Specification Specification
@ -221,9 +220,9 @@ keyword-only argument, which defaults to the current context::
# ... some time later # ... some time later
context.run(callback, *args) context.run(callback, *args)
Tasks in asyncio need to maintain their own isolated context that Tasks in asyncio need to maintain their own context that they inherit
they inherit from the point they were created at. ``asyncio.Task`` from the point they were created at. ``asyncio.Task`` is modified
is modified as follows:: as follows::
class Task: class Task:
def __init__(self, coro): def __init__(self, coro):
@ -395,7 +394,7 @@ Summary of the New APIs
parameter can be used to specify a custom context. parameter can be used to specify a custom context.
* ``asyncio.Task`` is modified internally to maintain its own * ``asyncio.Task`` is modified internally to maintain its own
isolated context. context.
Backwards Compatibility Backwards Compatibility