Simple tools for creating and managing decorators 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 decoratorbasic
Simple tools for creating and managing decorators in Python.
About The Project
Provides simple decorator 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 - CallableType has been used for advanced type checking.
Installation
- Clone the repo
git clone https://github.com/TahsinCr/python-decoratorbasic.git
- Install PIP packages
pip install decoratorbasic
Usage
Let's create a decorator named Timer
from typing import Any, Callable, TypeVar, Generic
import time
from decoratorbasic import (
DecoratorBasic, get_decorator_callable, get_decorators
)
TCallable = TypeVar('TCallable', bound=Callable)
class TimerDecorator(DecoratorBasic[TCallable], Generic[TCallable]):
def definator(self, callable:TCallable):
print(f"Add Decorator '{callable.__name__}': '{self.__class__.__name__}'")
return callable
def decorator(self, callable:TCallable, *args, **kwargs):
self.start = time.time()
result = callable(*args, **kwargs)
self.end = time.time()
print(f"Result '{callable.__name__}': {self.end - self.start}")
return result
@TimerDecorator()
def test_range(start:int, stop:int):
for n in range(start, stop): ...
@TimerDecorator()
class testo:
def __init__(self):
for n in range(1, 10000000):...
test_range(1,4000000)
print('DecoratorFunction: {}; BaseFuntion: {}'.format(test_range, get_decorator_callable(test_range)))
print('Decorators: {}'.format(str(get_decorators(test_range))))
testo()
Output
Add Decorator 'test_range': 'TimerDecorator'
Add Decorator 'testo': 'TimerDecorator'
Result 'test_range': 0.06389307975769043
DecoratorFunction: <function test_range at 0x000001C8395540E0>; BaseFuntion: <function test_range at 0x000001C839161440>
Decorators: [<__main__.TimerDecorator object at 0x000001C8393C1400>]
Result '__init__': 0.1724531650543213
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-decoratorbasic
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 decoratorbasic-1.0.1.tar.gz.
File metadata
- Download URL: decoratorbasic-1.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21afbbf10e7229f93ea78b695ae2529f875f78b8a760dfcce95b4c8c2541af9d
|
|
| MD5 |
329ff4110d59b8e31c164c4309c36a77
|
|
| BLAKE2b-256 |
53b86822e6d5b9937f781dfd1236a17963a1f57fc3d8217585c2abd0ad69c0a5
|
File details
Details for the file decoratorbasic-1.0.1-py3-none-any.whl.
File metadata
- Download URL: decoratorbasic-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 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 |
667d0eb938f8ed85a5dd92f0af5988b4b1296f27f72ddf5b6992482f6dadcc0b
|
|
| MD5 |
724157a0c5d205a399a393f5dcdd54ba
|
|
| BLAKE2b-256 |
58c8830651eb89d542be19311d3a1a16b412f4e5baa8f1d5fbb412c84434041e
|