delegatefn
A Python package for adding the parameters of a delegatee function to a delegator function, while keeping the original parameters of the delegator function.
Installation
To install delegatefn, use pip:
pip install delegatefn
Usage
To use the delegate decorator function, import it from delegatefn:
from delegatefn import delegate
Then, decorate your delegator function with the delegate decorator, passing in the delegatee function as an argument:
@delegate(delegatee)
def delegator(c: int, d: int, e: int, **kwargs):
...
The delegator function will now have the parameters of delegatee added to it, while keeping its original parameters.
You can also customize the behavior of the delegate decorator by passing in the following keyword arguments:
-
kwonly: A boolean value indicating whether the parameters of delegatee should be converted to keyword-only arguments. The default value isTrue. -
delegate_docstring: A boolean value indicating whether the docstring of delegatee should be used as the docstring of the delegator function. The default value isTrue. -
ignore: An iterable of strings containing the names of the parameters of delegatee that should be ignored. The default value is an empty set.
Here is an example of how to use these keyword arguments:
@delegate(delegatee, kwonly=True, delegate_docstring=True, ignore={"a", "b"})
def delegator(c: int, d: int, e: int, **kwargs):
...
Example
Here is an example of how to use the delegate decorator:
from delegatefn import delegate
def delegatee(a: int, b: int, **kwargs):
...
@delegate(delegatee)
def delegator(c: int, d: int, e: int, **kwargs):
...
The delegator function will now have the parameters a: int, b: int, and kwargs added to it, in addition to its original parameters c: int, d: int, and e: int.
Acknowledgements
This approach was inspired by fast.ai.
Metadata
Release files for delegatefn 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| delegatefn-0.4.2.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| delegatefn-0.4.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / delegatefn-0.4.2.tar.gz
| Download URL | delegatefn-0.4.2.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56527e61ed9f6a1f1c56fd4ddc680f4c5ea21c88989b743853e5ad922f103e48
|
|
BLAKE2b-256 checksum How to use checksums |
4cb856023ceb3e8a6b2c27261ef25a80b32ff224c0e83a494feb8dd3a50e048e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.11.0 Darwin/22.3.0
|
Release files / delegatefn-0.4.2-py3-none-any.whl
| Download URL | delegatefn-0.4.2-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28b97e62f06b0d8919c6502003c39ecd3ed4841cba633806fbc262c1bc16bf43
|
|
BLAKE2b-256 checksum How to use checksums |
c3f66e8f1cbaf08193aef843bc2fff83dd889b50ab963fd27adb0426873c7d7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.11.0 Darwin/22.3.0
|