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
File details
Details for the file delegate_property-0.1.0.tar.gz
.
File metadata
- Download URL: delegate_property-0.1.0.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52f2ab303b187e16c391356b114c69f410ff84560e0444ea8206f3196c08ffab |
|
MD5 | b4800f7b293480de7887ed89d8622dc1 |
|
BLAKE2b-256 | 0f27e752d3c4fbcb1ccf4fd590014a0d7558b779501e3c993143a4cccc990457 |
File details
Details for the file delegate_property-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: delegate_property-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf9628e14984abbb425f53f203bad6c586aa9daa2a1227b09ddc277cc51cb28d |
|
MD5 | a1dfa218de0acb9309a6dc3d6c97aa5b |
|
BLAKE2b-256 | 3ac7dc178d42c3bf2b30d4cb4e7fc2a82097e6b136636f28856a16c173296c42 |