Le 3 janv. 2018 06:34, "Guido van Rossum" <gu...@python.org> a écrit :

I think the issue here is a bit different than Yury's response suggests --
it's more like how a variable containing an immutable value (e.g. a string)
can be modified, e.g.

x = 'a'
x += 'b'

In our case the *variable* is the current thread state (in particular the
slot therein that holds the context -- this slot can be modified by the C
API). The *value* is the Context object. It is a collections.Mapping (or
typing.Mapping) which does not have mutating methods. (The mutable type is
called MutableMapping.)


I can see a parallel with a Python namespace, like globals and locals
arguments of exec():

ns = globals().copy()  # ctx = copy_context()
exec("x = 'a'", ns, ns)  # ctx.run(...)
ns['x'] += 'b'  # Context ???
print(ns ['x'])  # print(ctx[x])

The *reason* for doing it this way is that Yury doesn't want Context to
implement __delitem__, since it would complicate the specification of
chained lookups by a future PEP, and chained lookups look to be the best
option to extend the Context machinery for generators.


Again, why not just raise an exception on "del ctx[var]"?

Victor
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to