Skip to main content

strip-deco

license pypi pyversions badge Downloads


strip-deco easily strip decorator from function or class method

Installation

pip3 install strip-deco

Prototype

def stripdeco(obj: Any, depth: int = None, **kwargs) -> None:
    ...
  • obj: Function or Class method
  • depth: If your function is wrapped in multiple decorators, you can set how many decorators to disable through the depth parameter.
  • kwargs: Arguments that obj have to receive

Example of normal function

from strip_deco import stripdeco


def deco(func):
    def _deco(*args, **kwargs):
        result = func(*args, **kwargs)
        return result
    return _deco
    
@deco
def test():
    pass
    

stripdeco(obj=test)


@deco
@deco
@deco
def test():
    pass
    

stripdeco(obj=test)
stripdeco(obj=test, depth=1)  # Only strip one decorator

Example of class method

from strip_deco import stripdeco


def deco(func):
    def _deco(*args, **kwargs):
        result = func(*args, **kwargs)
        return result
    return _deco


class Service:
    @deco
    @deco
    def run(self):
        pass
    
    @deco
    @deco
    def run_with_arguments(self, user_id):
        pass


stripdeco(obj=Service().run)
stripdeco(obj=Service().run, depth=1)  # Only strip one decorator

stripdeco(obj=Service().run_with_arguments, user_id=1)  # Case of other arguments
stripdeco(obj=Service().run_with_arguments, depth=1, user_id=1)  # Only strip one decorator

Example of class method with init

from strip_deco import stripdeco


def deco(func):
    def _deco(*args, **kwargs):
        result = func(*args, **kwargs)
        return result
    return _deco


class Service:
    def __init__(self, repo):
        self.repo = repo

    @deco
    @deco
    def run(self):
        pass
    
    @deco
    @deco
    def run_with_arguments(self, user_id):
        pass

        
stripdeco(obj=Service(repo="repo").run)
stripdeco(obj=Service(repo="repo").run, depth=1)  # Only strip one decorator

stripdeco(obj=Service(repo="repo").run_with_arguments, user_id=1)  # Case of other arguments
stripdeco(obj=Service(repo="repo").run_with_arguments, depth=1, user_id=1)  # Only strip one decorator
  • strip-deco automatically removes any kind of decorators. (class/function)
  • It supports both decorator,functools wraps and non functools wraps .
  • If you specify depth paramater, it will strip order by outside.
  • The class argument is required when executing class method.

Release files for strip-deco 0.0.9

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

Source distribution (sdist)

Source distribution for strip-deco 0.0.9
File Size Uploaded
strip-deco-0.0.9.tar.gz 3.5 kB Details

Release files / strip-deco-0.0.9.tar.gz

Download URL strip-deco-0.0.9.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
828e75fdc88d714b24188e1c96879c25b734e6faaddb938e037b279661ff3075
BLAKE2b-256 checksum
How to use checksums
a67f40ee9474a6ea559291f0b7dbba60cd6ab26804d7c74508d7c538fffdafe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.9 This release

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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