pep-567: Merge "Design Considerations" and "Rejected Ideas" (#551)

The "Design Considerations" section had only one subsection which
was a discussion of a rejected idea.  Merging it into "Rejected Ideas"
simplifies the document structure.

Fix a bug in a code snippet in the "ContextVar.unset()" subsection.

Adjust titles in the Rejected Ideas section.
This commit is contained in:
Yury Selivanov 2018-01-18 13:49:51 -05:00 committed by Guido van Rossum
parent 0c70f909df
commit 2bd2b7eb7d
1 changed files with 22 additions and 26 deletions

View File

@ -573,25 +573,30 @@ C API
if (PyContext_Exit(old_ctx)) goto error;
Design Considerations
=====================
Rejected Ideas
==============
Why contextvars.Token and not ContextVar.unset()?
-------------------------------------------------
Replication of threading.local() interface
------------------------------------------
Please refer to :pep:`550` where this topic is covered in detail: [2]_.
Replacing Token with ContextVar.unset()
---------------------------------------
The Token API allows to get around having a ``ContextVar.unset()``
method, which is incompatible with chained contexts design of
:pep:`550`. Future compatibility with :pep:`550` is desired
(at least for Python 3.7) in case there is demand to support
context variables in generators and asynchronous generators.
in case there is demand to support context variables in generators
and asynchronous generators.
The Token API also offers better usability: the user does not have
to special-case absence of a value. Compare::
token = cv.get()
token = cv.set(new_value)
try:
cv.set(blah)
# code
# cv.get() is new_value
finally:
cv.reset(token)
@ -609,17 +614,8 @@ with::
cv.set(old)
Rejected Ideas
==============
Replication of threading.local() interface
------------------------------------------
Please refer to :pep:`550` where this topic is covered in detail: [2]_.
Token.reset() instead of ContextVar.reset()
-------------------------------------------
Having Token.reset() instead of ContextVar.reset()
--------------------------------------------------
Nathaniel Smith suggested to implement the ``ContextVar.reset()``
method directly on the ``Token`` class, so instead of::
@ -643,8 +639,8 @@ being clearer to the human reader of the code which variable is
being reset.
Make Context objects picklable
------------------------------
Making Context objects picklable
--------------------------------
Proposed by Antoine Pitrou, this could enable transparent
cross-process use of ``Context`` objects, so the
@ -667,8 +663,8 @@ Given the time frame of the Python 3.7 release schedule it was decided
to defer this proposal to Python 3.8.
Make Context a MutableMapping
-----------------------------
Making Context a MutableMapping
-------------------------------
Making the ``Context`` class implement the ``abc.MutableMapping``
interface would mean that it is possible to set and unset variables
@ -713,8 +709,8 @@ This proposal was deferred to Python 3.8+ because of the following:
ctx.run(func)
Have initial values for ContextVars
-----------------------------------
Having initial values for ContextVars
-------------------------------------
Nathaniel Smith proposed to have a required ``initial_value``
keyword-only argument for the ``ContextVar`` constructor.