Simple tools for creating and managing decorator functions in Python.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
Python DecoratorFunc
Simple tools for creating and managing decorator functions in Python.
About The Project
Provides simple decorator function utilities for Python 3.x.
Built With
Getting Started
To get a local copy up and running follow these simple example steps.
Prerequisites
- Python-lib - DecoratorBasic has been used for basic decorator utilities.
Installation
- Clone the repo
git clone https://github.com/TahsinCr/python-decoratorfunc.git
- Install PIP packages
pip install decoratorfunc
Usage
Let's create a decorator named Timer
import time
from decoratorbasic import get_decorators, get_decorator_callable
from decoratorfunc import definator, decorator, is_decoratorfunc
@definator
def time_decorator(func):
# The DecoratorFuncBasic class is automatically created.
# It is named according to PEP8 conventions by using the function's name (time_decorator -> TimeDecorator).
# The generated DecoratorFuncBasic class can be accessed via time_decorator.__class__.
print(f"Add Decorator '{func.__name__}': '{time_decorator.__class__.__name__}'")
return func
@time_decorator.decorator
def time_decorator(func, *args, **kwargs):
# A function defined with the definator/decorator will return a DecoratorFuncBasic class.
# This allows the function to be redefined using the definator/decorator again. (time_decorator.decorator/time_decorator.definator)
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"Result '{callable.__name__}': {end - start}")
return result
# Since the time_decorator function returns the DecoratorFuncBasic class, the __call__ method of this class is used as a decorator.
# In this way, the DecoratorFuncBasic class behaves like DecoratorBasic and fulfills the decorator functionality.
@time_decorator
def test_range(start:int, stop:int):
for n in range(start, stop): ...
@time_decorator
class testo:
def __init__(self):
for n in range(1, 10000000):...
test_range(1,4000000)
decoratorbases = get_decorators(test_range)
print('IsDecoratorFunc:', is_decoratorfunc(decoratorbases[0]))
testo()
Output
Add Decorator 'test_range': 'TimeDecorator'
Add Decorator 'testo': 'TimeDecorator'
Result 'callable': 0.10388374328613281
IsDecoratorFunc: True
Result 'callable': 0.1656045913696289
For more examples, please refer to the Documentation
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Tahsin Çirkin - @TahsinCrs - TahsinCr@outlook.com
Project: TahsinCr/python-decoratorfunc
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 decoratorfunc-1.0.tar.gz.
File metadata
- Download URL: decoratorfunc-1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff486aa252760665961dbefe3069dd31009e9d474f0ced162d8b95ed209687ce
|
|
| MD5 |
9c3fa0ce6e3a4c6b4856ba184247d8a8
|
|
| BLAKE2b-256 |
39e7884660f10e7282a46721660e1ab7d80cd81f6ed1681c5a762d278e67e2e1
|
File details
Details for the file decoratorfunc-1.0-py3-none-any.whl.
File metadata
- Download URL: decoratorfunc-1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59cbb32dd51962a969626e250baf91c12c94692b0d699cf7077f04ef39931ac3
|
|
| MD5 |
b978714d5270935ff0785c444cd55cd9
|
|
| BLAKE2b-256 |
f81f97554d49165aba6673d7086137ade4a1a6897e90f3a73bc8aa5b5a7ed039
|