This construct has some similarities with instance member class (known from Java, but available in Python as well). But instead of having a separate class created for each instance I think there may be some benefit of having the actual class being shared and instead just have a reference to the "owner" instance.
The construct looks something like:
def fubar(cls):
def init(own, *args, **kwds):
return cls(own, *args, **kwds)
return init
class Outer:
@fubar
class Inner:
def __init__(self, own, *args, **kwds):
self._owner = own
Then if you have an instance o
of Outer
you would be able to create an instance of Inner
by calling i=o.Inner(*args, **kwds)
and i._owner
would automagically be assigned to o
.
Now does this construct/idiom have a recognized name? That is is there a proper name to be used instead of fubar
?