A convenient way to create parametrized decorators.
Project description
Paramdec is a convenient way to create parametrized decorators.
Usage
Create your parametrized decorator:
>>> from paramdec import paramdec >>> @paramdec ... def my_dec(func, foo=42, bar=None): ... def wrapper(*func_args, **func_kwargs): ... # Process foo and bar ... return func(*func_args, **func_kwargs) ... return wrapper
Use it with parameters:
>>> @my_dec(bar="bar") >>> def func(): pass
Or without parameters:
>>> @my_dec() >>> def func(): pass
Or even without parentheses:
>>> @my_dec >>> def func(): pass
Also, consider using functools.wraps for your decorators.
Limitations
No positional args supported.
The rationale behind this is the fact that I have not found any pythonic way to make a decorator differentiate between a function to be decorated and a callback. So if you pass a single callable positional argument to a parametrized decorator, it will mistakenly decide that it was called not as a factory but as a casual decorator.
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 Distributions
Built Distribution
File details
Details for the file paramdec-2.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: paramdec-2.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 717a07551182ca16dc45d30b207dd8cd3706da9998ac3ec7f06ea81d77d34206 |
|
MD5 | 4178cb5b647ce39bedda6df9d59e4049 |
|
BLAKE2b-256 | a98cc59390dfbb53f858d1b6b7217f74163b90c588f195b11121a61108120033 |