delegator is a micro-package for defining delegated methods and attributes.
In short, it serves to get rid of boilerplate such as the one on the left hand side with the compact notation on the right hand side. It's very similar to delegation syntax in Ruby.
delegate attribue on the delegating class can be a sequence or a single string with arguments separated by whitespace (similar to
namedtuple). Delegatee attribute must be the first argument. If you don't like the style - no worries - there are three interchangeable notations:
class Foo(metaclass=Delegator): delegate = 'bar spam ham eggs' # or delegate = 'bar', 'spam', 'ham', 'eggs'
Explicit class decorator
@delegate('bar spam ham eggs') # or @delegate('bar', 'spam', 'ham', 'eggs') class Foo(metaclass=Delegator):
Implicit class decorator
@delegator class Foo: delegate = 'bar spam ham eggs' # or, again: delegate = 'bar', 'spam', 'ham', 'eggs'
Internally, delegation works via simple attribute accessors with
__delete__ methods. Setting and deleting works as expected:
foo.spam = 'chopped pork and ham' foo.spam # = 'chopped pork and ham' del foo.spam foo.spam # = 'spam' (falls back to `spam` attribute on `Bar`)
For more details, see
Delegated in the source code. For more examples, check out
You can get it from PyPI:
pip install dele-gator # delegator was taken
Or install directly from GitHub:
pip install git+https://github.com/IwoHerka/delegator@master