This package contains the main functionalities
Project description
Decogreat
This project aims to simplify how decorators are made. I apologize in advance for all the type: ignore but it is quite a challenge to properly type hint in metaprogramming...
Getting started
1 - Install Decogreat
pip intall decogreat
2 - Create a decorator function with the behavior you want for your decorator.
from decogreat import to_decorator
from collections.abc import Callable
def my_decorator_function(
decorated_function: Callable,
function_args: list,
function_kwargs: dict,
decorator_args: list,
decorator_kwargs: dict
):
"""
Code your decorator here
Parameters
----------
function_args : list
The arguments of the decorated function.
function_kwargs : dict
The keyword arguments of the decorated function.
decorator_args : list
The arguments of the decorator.
decorator_kwargs : dict
The keyword arguments of the decorator.
"""
print("Function args:", function_args)
print("Function kwargs:", function_kwargs)
print("Decorator args:", decorator_args)
print("Decorator kwargs:", decorator_kwargs)
# Don't forget to call the decorated function
return decorated_function(*function_args, **function_kwargs)
3 - Call decorify with your decorator function to create your decorator
my_decorator = to_decorator(my_decorator_function)
4 - Use your decorator
@my_decorator("decorator arg", keyword_arg="a kw arg")
def decorated_function(arg1: str, arg2: int) -> float:
"""
A function decorated
"""
print("Decorated function called")
return 0.6
5 - Whenever the function is called, the decorator function is called.
result = decorated_function("some string", arg2=42)
print(f"Result: {result}")
Function args: ('some string',)
Function kwargs: {'arg2': 42}
Decorator args: ('decorator_arg',)
Decorator kwargs: {'keyword_arg':'a kw arg'}
Decorated function called
Result: 0.6
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file decogreat-0.1.1.tar.gz.
File metadata
- Download URL: decogreat-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56ca51d4dec216cb3a03d11c5e5c3c1dbd6c176633541aa793e49cbe5326598d
|
|
| MD5 |
6eea757073d1e6195cb7b22726b3a650
|
|
| BLAKE2b-256 |
cc99241d0a93998017f1dcc0111232b100d4e4d3cc5c2634cdba962ec832fbd7
|
File details
Details for the file decogreat-0.1.1-py3-none-any.whl.
File metadata
- Download URL: decogreat-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
970dc67acf0f1318d1ec3dac3a59fd28419834108708088e8cf0f50169f38a43
|
|
| MD5 |
eb90396a4c3da15a3300485b97d5e2cb
|
|
| BLAKE2b-256 |
4ed4b363cff438b5fffa179a24bbb2b6ffd81af6df29d98db32ae72b1ca9b03c
|