Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dscottboggs/python-delegate
Delegate properties on a class to the attributes of one of its members
https://github.com/dscottboggs/python-delegate
code-generation metaprogramming python
Last synced: about 1 month ago
JSON representation
Delegate properties on a class to the attributes of one of its members
- Host: GitHub
- URL: https://github.com/dscottboggs/python-delegate
- Owner: dscottboggs
- License: mit
- Created: 2019-06-13T15:29:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-19T16:51:41.000Z (over 2 years ago)
- Last Synced: 2024-10-01T09:24:38.907Z (about 1 month ago)
- Topics: code-generation, metaprogramming, python
- Language: Python
- Size: 3.91 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:```python
from delegate import delegateclass 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 = Trueassert raised
```