[Python-Dev] PEP 567 v2
Victor Stinner
victor.stinner at gmail.com
Thu Dec 28 04:51:52 EST 2017
Hi,
I like the new version of the PEP using "read only mapping" and
copy_context(). It's easier to understand.
I'm ok with seeing a context as a mapping, but I am confused about a
context variable considered as a mapping item. I still see a context
variable as a variable, so something which has a value or not. I just
propose to rename the default parameter of the ContextVar constructor.
Le 28 déc. 2017 7:10 AM, "Yury Selivanov" <yselivanov.ml at gmail.com> a
écrit :
ContextVar
----------------------
The ``ContextVar`` class has the following constructor signature:
``ContextVar(name, *, default=_NO_DEFAULT)``. The ``name`` parameter
is used only for introspection and debug purposes, and is exposed
as a read-only ``ContextVar.name`` attribute. The ``default``
parameter is optional. Example::
# Declare a context variable 'var' with the default value 42.
var = ContextVar('var', default=42)
In term of API, "default" parameter name is strange. Why not simply calling
it "value"?
var = ContextVar('var', default=42)
and:
var = ContextVar('var')
var.set (42)
behaves the same, no?
The implementation explains where the "default" name comes from, but IMHO
"value" is a better name.
(The ``_NO_DEFAULT`` is an internal sentinel object used to
detect if the default value was provided.)
I would call it _NOT_SET.
* a read-only attribute ``Token.old_value`` set to the value the
variable had before the ``set()`` call, or to ``Token.MISSING``
if the variable wasn't set before.
Hum, I also suggest to rename Token.MISSING to Token.NOT_SET. It would be
more conistent with the last sentence.
C API
-----
Would it be possible to make this API private?
2. ``int PyContextVar_Get(PyContextVar *, PyObject *default_value,
PyObject **value)``:
(...) ``value`` is always a borrowed
reference.
I'm not sure that it's a good idea to add a new public C function which
returns a borrowed reference. I would prefer to only use (regular) strong
references in the public API.
I don't want to elaborate here. You may see:
http://vstinner.readthedocs.io/python_new_stable_api.html
Internally, I don't care, do whatever you want for best performances :-)
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171228/2fc8ec86/attachment-0001.html>
More information about the Python-Dev
mailing list