[Python-ideas] A "within" keyword

Jelle Zijlstra jelle.zijlstra at gmail.com
Sat Jun 9 00:46:45 EDT 2018

2018-06-08 20:27 GMT-07:00 Alex Walters <tritium-list at sdamon.com>:

> Why not...
> cool_namespace = SomeNamespaceContextManager()
> with cool_namespace:
>     def foo():
>         pass
> advantage being it introduces no new keyword.  The 'disadvantage' is it
> would change semantics of the with statement (as would be required to get
> the names defined in the suite of the context manager)
> Actually, this is probably doable now. You can get the globals of the
calling code by doing sys._getframe(), then check which names are added
while the context manager is active.

> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180608/89184073/attachment-0001.html>

More information about the Python-ideas mailing list