delegate attributes of a class to another attribute's properties
Project description
Delegate
A python library for delegation (the metaprogramming feature)
This library adds the @delegate
decorator which may be used to delegate
attributes from an attribute of the existing class. For example:
from delegate import delegate
class Parent:
def __init__(self):
self.a = "a"
self.b = "b"
self.d = "d"
# The delegate decorator makes .a and .b available on Child, through its
# "parent" attribute, as though Child had an a and b attribute itself.
@delegate("a", "b", to="parent")
class Child:
def __init__(self):
self.parent = Parent()
self.c = "c"
instance = Child()
assert instance.a == "a"
raised = False
try:
# But d is not available
instance.d
except e:
raised = True
assert raised
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for delegate_property-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf9628e14984abbb425f53f203bad6c586aa9daa2a1227b09ddc277cc51cb28d |
|
MD5 | a1dfa218de0acb9309a6dc3d6c97aa5b |
|
BLAKE2b-256 | 3ac7dc178d42c3bf2b30d4cb4e7fc2a82097e6b136636f28856a16c173296c42 |