Easily strip decorator from function or class method
Project description
strip-deco
strip-deco easily strip decorator from function or class method
Installation
pip3 install strip-deco
Example of function decorator
from strip_deco import stripdeco, run_after_strip
def deco(func):
def _deco(*args, **kwargs):
result = func(*args, **kwargs)
return result
return _deco
@deco
def test():
pass
stripped_func = stripdeco(obj=test)
stripped_func()
# OR
run_after_strip(obj=test)
@deco
@deco
@deco
def test():
pass
stripped_func = stripdeco(obj=test, depth=2) # It will only strip two decorator
stripped_func()
# OR
run_after_strip(obj=test)
Example of class decorator
from strip_deco import stripdeco, run_after_strip
class Deco:
def __call__(self, func):
def deco(*args, **kwargs):
return func(*args, **kwargs)
return deco
@Deco()
def test():
pass
stripped_func = stripdeco(obj=test)
stripped_func()
# OR
run_after_strip(obj=test)
@Deco()
@Deco()
@Deco()
def test():
pass
stripped_func = stripdeco(obj=test, depth=2) # It will only strip two decorator
stripped_func()
# OR
run_after_strip(obj=test, depth=2)
Example of class method
from strip_deco import stripdeco, run_after_strip
def deco(func):
def _deco(*args, **kwargs):
result = func(*args, **kwargs)
return result
return _deco
class Service:
@deco
def run(self):
pass
@deco
def run_with_arguments(self, user_id):
pass
stripped_func = stripdeco(obj=Service.run)
stripped_func(Service()) # Must add class instance through first argument
# OR
run_after_strip(obj=Service().run)
stripped_func = stripdeco(obj=Service.run_with_arguments)
stripped_func(Service(), user_id=1) # Case of other arguments
# OR
run_after_strip(obj=Service().run_with_arguments, user_id=1)
Ex
Example of class method with init
from strip_deco import stripdeco, run_after_strip
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
def run(self):
pass
@deco
def run_with_arguments(self, user_id):
pass
stripped_func = stripdeco(obj=Service.run)
stripped_func(Service(repo="repo")) # Must add class instance through first argument
# OR
run_after_strip(obj=Service(repo="repo").run)
stripped_func = stripdeco(obj=Service.run_with_arguments)
stripped_func(Service(repo="repo"), user_id=1) # Case of other arguments
# OR
run_after_strip(obj=Service(repo="repo").run_with_arguments, user_id=1)
- 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.
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
strip-deco-0.0.7.tar.gz
(3.7 kB
view details)
File details
Details for the file strip-deco-0.0.7.tar.gz
.
File metadata
- Download URL: strip-deco-0.0.7.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d97ea7b8a477bb4567cd6b25fe2c430da8097e2decf3cbc18c67acecf6b6d247 |
|
MD5 | 1741890c8cef0c8e969283a91b42ae96 |
|
BLAKE2b-256 | f9db0453b06971ac02709b930f3b21b0717b09a0aaf81bfefd3562867106dd48 |