On 26/07/2019 08:13, Batuhan Taskaya wrote:
I am proposing namespace context managers with implementing `__enter__` and `__exit__` on dict objects.
Didn't we have this discussion recently? What do these __enter__() and __exit__() do? Please don't answer with an example, I want to understand what this mechanism is supposed to achieve.
Also, I can't tell if you're proposing to add __enter__ and __exit__ to dict objects or have the "with" statement magically add them. Is it just dicts, or will any mapping type do?
It would make closures possible in python with a pythonic syntax. a = 4 namespace = {} with namespace: a = 3 assert a == 4 assert namespace["a"] == 3
Right, so it's in effect supplying a different dictionary for local variables. How do these stack? Innermost namespace takes priority? Are outer namespaces accessible using nonlocal? How does this interact with other sorts of namespaces?
I don't think dicts are the right place to start. I think you want a specialised namespace object that supplies a mapping interface. That gives you a lot more flexibility when it comes to implementation, amongst other things.
(I'm not actually very keen on namespaces like this, personally. Too much debugging of C++ code has made me very twitchy about unstructured names. That's besides the point, though.)
-- Rhodri James *-* Kynesim Ltd _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XKE2D6JEE6464I66F5FOBB4BWX654L7X/ Code of Conduct: http://python.org/psf/codeofconduct/