[Python-ideas] A "within" keyword
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():
> 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
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas