libb.delegate
- delegate(deleg, attrs)[source]
Delegate attribute access to another object.
Creates properties that forward attribute access to a specified delegate object, enabling composition over inheritance.
- Parameters:
- Return type:
Delegate Simple Attributes:
>>> class X: ... a = 1 >>> class Y: ... x = X() ... delegate('x', 'a') >>> Y().a 1
Delegate Methods:
>>> class A: ... def echo(self, x): ... print(x) >>> class B: ... a = A() ... delegate('a', ['echo']) >>> B().echo('whoa!') whoa!