Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Contributors Forks Stargazers Issues MIT License LinkedIn

Python DecoratorFunc

Simple tools for creating and managing decorator functions in Python.

Changelog · Report Bug · Request Feature

About The Project

Provides simple decorator function utilities for Python 3.x.

Built With

  • python-shield

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

  1. Clone the repo
git clone https://github.com/TahsinCr/python-decoratorfunc.git
  1. 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

Release files for decoratorfunc 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decoratorfunc 1.0
File Size Uploaded
decoratorfunc-1.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for decoratorfunc 1.0
File Interpreter ABI Platform
decoratorfunc-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / decoratorfunc-1.0.tar.gz

Download URL decoratorfunc-1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ff486aa252760665961dbefe3069dd31009e9d474f0ced162d8b95ed209687ce
BLAKE2b-256 checksum
How to use checksums
39e7884660f10e7282a46721660e1ab7d80cd81f6ed1681c5a762d278e67e2e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / decoratorfunc-1.0-py3-none-any.whl

Download URL decoratorfunc-1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59cbb32dd51962a969626e250baf91c12c94692b0d699cf7077f04ef39931ac3
BLAKE2b-256 checksum
How to use checksums
f81f97554d49165aba6673d7086137ade4a1a6897e90f3a73bc8aa5b5a7ed039
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page