Skip to main content

Useful decorators for your application.

Project description

DecMore

This library contains some decorators that will be useful for both daily development and application needs.

Decorators

CheckTypes:

This decorator checks if the types of the variables sent are the same as the ones the function needs

Example:

from DecMore import CheckTypes


@CheckTypes
def func(var1: str, var2: list, var3: list | tuple):
    ...


if __name__ == "__main__":
    func(1, [], var3=None)

    """ The execution will return a TypeError like this
    
    TypeError: 
    Param 'var1' Expected <class 'str'>, got <class 'int'> instead
    Param 'var3' Expected <class 'list'> or <class 'tuple'>, got <class 'NoneType'> instead
    
    """

Profiler:

This decorator shows how long each line of your function took to execute

Example:

from time import sleep
from DecMore import Profiler


@Profiler()
def func():
    sleep(10)


if __name__ == "__main__":
    func()

    """ The execution will show the data on the console like this
    
     3 function calls in 10.009 seconds
  
     Ordered by: internal time
  
     ncalls  tottime  percall  cumtime  percall filename:lineno(function)
          1   10.009   10.009   10.009   10.009 {built-in method time.sleep}
          1    0.000    0.000   10.009   10.009 main.py:4(func)
          1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
    """

Authors

Daniel Relvas Trivelli

License

This project is under the MIT license. See the file LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decmore-0.1.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

decmore-0.1.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page