[Python-Dev] PEP 567 v2 (original) (raw)

Victor Stinner victor.stinner at gmail.com
Wed Jan 3 04:49:11 EST 2018


Le 3 janv. 2018 06:34, "Guido van Rossum" <guido at 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180103/6700c761/attachment.html>



More information about the Python-Dev mailing list