Overview:
class Inner(object):
def __init__(self, x):
self.x = x
class Outer(object):
def __init__(self, z):
self.inner = Inner(z)
o = Outer(10)
Now, I want the Outer object to behave transparently -- any attributes set on o should be set on o.inner, same for reading: o.something should return, in fact, the value of o.inner.sommething. Kind of like a proxy or a relay.
__getattr__ for Outer seems simple & works:
def __getattr__(self, item):
return getattr(self, item)
How would I handle __setattr__? I couldn't come up with anything that didn't cause a recursion error and make me hate myself.
Or is the concept itself flawed?
(Another approach I tried was making Outer a subclass of Inner -- this didn't really play aesthetically the present@classmethods, not to mention the IDE would get lost inside those - not able to resolve some attributes. Let's leave that for now, perhaps?)