On Fri, Jul 26, 2019 at 10:52:46AM -0400, Calvin Spealman wrote: > Let's say you do this or any of the variants suggested... What does this do? > > a = {"foo": 1} > b = {} > with a: > with b: > foo = 0
Re-writing that to my suggested version: with namespace("a") as a: with namespace("b") as b: foo = 0 will create a namespace object (a subclass of ModuleType) and bind it to "a", containing a namespace object "b", containing a variable "foo": assert isinstance(a, NamespaceType) assert isinstance(a.b, NamespaceType) assert a.b.foo == 0 That would be analogous to this existing code: class a: class b: foo = 0 except classes have different scoping rules to modules. -- Steven _______________________________________________ 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/W3XEBOHQS3AWJ3Z26GA3H24GBGECM6FL/ Code of Conduct: http://python.org/psf/codeofconduct/