Smart Decorator
A static-typed library for creating decorators.
from smart_decorator import simple_decorator
_events = {}
@simple_decorator
def register(callback, *, event_type: str = 'normal'):
_events[event_type] = callback
return callback
@register # Parentheses optional
def on_normal():
print('an event happened!')
@register(event_type='error')
def on_error():
print('an error!')
# can be used as a normal function, too
def on_close():
print('closing!')
register(on_close, event_type='close')
Documentation
@simple_decorator
Turn a function into a smart decorator, as shown above. The decorator must accept a func, and some optional keyword arguments. Simple decorators must either return the func unchanged, or a wrapper with the same signature (see @decorator for signature morphing!).
@simple_decorator
def my_function(func, *, option1, option2 = ...):
def wrapper(*args, **kwargs):
... # do something
return func(*args, **kwargs)
return wrapper
@decorator
The same as @simple_decorator but the decorator can return anything, such as a function with a different signature. Decorators declared this way should ideally be static-typed.
@decorator
def inject_foo[**P, R](
func: Callable[Concatenate[str, P], R], # static-typing to inject a parameter
*,
what_to_inject: str = 'foo'
) -> Callable[P, R]:
def wrapper_func(*args: P.args, **kwargs: P.kwargs) -> R:
return func(what_to_inject, *args, **kwargs)
return wrapper_func
@inject_foo
def add_stuff(what: str, cool: str) -> str:
return what + cool
assert add_stuff('bar') == 'foobar'
Metadata
Release files for smart-decorator 0.1.0
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 |
|---|---|---|---|---|
| smart_decorator-0.1.0.tar.gz | 4.5 kB | With provenance | Details for smart_decorator-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smart_decorator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for smart_decorator-0.1.0-py3-none-any.whl |
Total release size: 12.4 kB
Release files / smart_decorator-0.1.0.tar.gz
| Download URL | smart_decorator-0.1.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
697da5713803ff021f1e175c16149808bb00b5eddaee079b76b48c724fc5e60f
|
|
BLAKE2b-256 checksum How to use checksums |
6d87569ab6133ee3c09f1e51f7233a381bd2cdd364b88c21b340a201ed273c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 31, 2025.
Transparency logRelease files / smart_decorator-0.1.0-py3-none-any.whl
| Download URL | smart_decorator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ec28b08470a58ec390cb12f1ca6d537509b0217673555a3cd15f5a042d0b512
|
|
BLAKE2b-256 checksum How to use checksums |
a5c1014bab820c7bc623e24d5984bb349a30f3ace87c07b0fce38cf8086b0a06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 31, 2025.
Transparency logSecurity for smart-decorator 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for smart_decorator-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 31, 2025.
Transparency logA 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.