28 Jul
2019
28 Jul
'19
9:33 p.m.
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