I wrote some wrapper which has another object as an attribute. This wrapper proxies (forwards) all attribute requests with __getattr__ and __setattr__
Generally, you can use the wrapt library (pypi), which does the heavy lifting for you:
The wrapt module focuses very much on correctness. It therefore goes way beyond existing mechanisms such as functools.wraps() to ensure that decorators preserve introspectability, signatures, type checking abilities etc. [...]
To ensure that the overhead is as minimal as possible, a C extension module is used for performance critical components
It supports creating custom wrapper classes. In order to add your own attributes, you need to declare them in such a way that wrapt doesn't try to pass them on to the wrapped instance. You can:
_self_ and add properties for access__init__Use slots, if appropriate for your class (not mentioned in the docs), like this:
class ExtendedMesh(ObjectProxy):
__slots__ = ('foo')
def __init__(self, subject):
super().__init__(subject)
self.foo = "bar"
It also supports function wrappers, which might suit your purpose.