decohints
A decorator for decorators that allows you to see the parameters of a decorated function when using it in PyCharm.
PyPi: https://pypi.org/project/decohints/
Reasons for creation
Below is an example of a decorator with parameters without the use of decohints:
from functools import wraps
def decorator_with_params(aa=None, bb=None, cc=None):
def _decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
except Exception:
print("Error")
return
return result
return wrapper
return _decorator
@decorator_with_params()
def test(a: int, b: int) -> int:
return a + b
If you type below test() in PyCharm and wait, it will show decorator wrapper parameter hints as test function
parameter hints:
This is not convenient and can confuse developers, which is why this library was made.
Installation
pip install decohints
Usage
✅ Works with all kinds of decorators
⚠️ If your decorator is already wrapped in another decorator, thendecohintsshould be on top
To use, you need to follow two simple steps:
- Import the
decohintsdecorator from thedecohintslibrary:
from decohints import decohints
- Wrap your decorator with a
decohintsdecorator:
@decohints
def your_decorator():
...
The following is an example of a decorator with parameters, with using decohints:
from functools import wraps
from decohints import decohints
@decohints
def decorator_with_params(aa=None, bb=None, cc=None):
def _decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
except Exception:
print("Error")
return
return result
return wrapper
return _decorator
@decorator_with_params()
def test(a: int, b: int) -> int:
return a + b
If you type below test() in PyCharm and wait, it will show test function parameter hints:
❕Examples of use with decorator class, class decorators, and more are found at here: click
Alternatives
Specifying the type of wrapper
✅ Works with all kinds of decorator functions
Specifying the type wrapper: func will have the same behavior as using decohints.
Example:
from functools import wraps
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
except Exception:
print("Error")
return
return result
wrapper: func
return wrapper
@decorator
def test(a: int, b: int) -> int:
return a + b
If you type below test() in PyCharm and wait, it will show test function parameter hints:
Specifying an output type in a decorator with parameters
❗️This method only works in decorator functions with parameters
If you specify the Callable type from the typing module for the result of the decorator with parameters, then the
behavior will be the same as using decohints.
Example:
from functools import wraps
from typing import Callable
def decorator_with_params(aa=None, bb=None, cc=None) -> Callable:
def _decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
except Exception:
print("Error")
return
return result
return wrapper
return _decorator
@decorator_with_params()
def test(a: int, b: int) -> int:
return a + b
If you type below test() in PyCharm and wait, it will show test function parameter hints:
Metadata
Release files for decohints 1.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| decohints-1.0.9.tar.gz | 7.1 kB | Without provenance | Details for decohints-1.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| decohints-1.0.9-py3-none-any.whl | Python 3 | none | any | Details for decohints-1.0.9-py3-none-any.whl |
Total release size: 14.4 kB
Release files / decohints-1.0.9.tar.gz
| Download URL | decohints-1.0.9.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e066715f003ddef965fce223d1e83bf9102f8bfb5be3e98bc545aef58fca944
|
|
BLAKE2b-256 checksum How to use checksums |
56f0791ba6f965487a81c3b494a5c14354f99bc57418d79ab903e72da4b0d4d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.4
|
Release files / decohints-1.0.9-py3-none-any.whl
| Download URL | decohints-1.0.9-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3007256b1b179ccca9e240ea4117c8b59cd31e32de9129c95bbbb867f320c922
|
|
BLAKE2b-256 checksum How to use checksums |
9b7bd4358edcd028eb4313f91d9972d976e81f3dbfb1035a5511f31f73f248b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.4
|
Security for decohints 1.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.