Debugger as decorator for functions and methods
Project description
Overview
This package is created to make the debug process much easier for python projects.
Algorithm
This package imports @debug decorator for functions and methods, which:
- Prints all arguments taken by function and their types.
- Show how long is instance running in seconds.
- Catches and prints out detailed information about all exceptions.
- Prints out all returned values and their types.
Usage
- Import debug from clevdebug library:
from clevdebug import debug - Add
@debugdecorator to the function or method:@debug - Run the script.
Examples
There are several usage cases.
Simple Example
# import debug from clevdebug
from clevdebug import debug
# Debugger for function
@debug
def foob(a, b):
return b
# Debugger for method in class
class Boof:
@debug
def __init__(a, b) -> None:
pass
if __name__ == '__main__':
boo = Boof(1, b = 2)
foob(1, 2)
Output is:
2022-10-29 19:27:49,521 debugger of foo wrapper on line 20: ========================================
2022-10-29 19:27:49,521 debugger of foo wrapper on line 21: Calling [<class 'function'>]foo:
2022-10-29 19:27:49,521 debugger of foo wrapper on line 37: There are 2 arguments:
2022-10-29 19:27:49,521 debugger of foo wrapper on line 40: a: [<class 'int'>] 5
2022-10-29 19:27:49,521 debugger of foo wrapper on line 40: b: [<class 'int'>] 4
2022-10-29 19:27:49,521 debugger of foo wrapper on line 43: Running foo takes: 0.00000
2022-10-29 19:27:49,521 debugger of foo wrapper on line 45: Result is: [<class 'int'>]4
2022-10-29 19:27:49,521 debugger of foo wrapper on line 58: ========================================
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 20: ========================================
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 21: Calling [<class 'function'>]__init__:
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 37: There are 2 arguments:
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 40: a: [<class 'int'>] 5
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 40: b: [<class 'int'>] 4
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 43: Running __init__ takes: 0.00000
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 47: There is no return.
2022-10-29 19:27:49,521 debugger of __init__ wrapper on line 58: ========================================
Catching errors
# import debug from clevdebug
from clevdebug import debug
# Debugger for function
@debug
def foob(a, b):
return b/0
if __name__ == '__main__':
foob(1, 2)
Output is:
2022-10-29 19:37:47,173 debugger of foob wrapper on line 20: ========================================
2022-10-29 19:37:47,173 debugger of foob wrapper on line 21: Calling [<class 'function'>]foob:
2022-10-29 19:37:47,173 debugger of foob wrapper on line 37: There are 2 arguments:
2022-10-29 19:37:47,173 debugger of foob wrapper on line 40: a: [<class 'int'>] 1
2022-10-29 19:37:47,173 debugger of foob wrapper on line 40: b: [<class 'int'>] 2
2022-10-29 19:37:47,174 debugger of foob wrapper on line 54: Exception type : ZeroDivisionError
2022-10-29 19:37:47,174 debugger of foob wrapper on line 55: Exception message : division by zero
2022-10-29 19:37:47,174 debugger of foob wrapper on line 56: Stack trace : ['File : PATH/main.py , Line : 42, Name : wrapper, Message : result = func(*args, **kwargs)', 'File : /PATH/dev.py , Line : 6, Name : foob, Message : return b/0']
2022-10-29 19:37:47,174 debugger of foob wrapper on line 58: ========================================
Do not use to class
from clevdebug import debug
@debug
class A:
def __init__(self, a, b):
self.a = a
self.b = b
if __name__ == '__main__':
A(1, 2)
Output is:
TypeError: Only functions or methods INSIDE a class can be debugged
Installation
pip install clevdebug
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
clevdebug-0.0.2.tar.gz
(4.5 kB
view details)
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 clevdebug-0.0.2.tar.gz.
File metadata
- Download URL: clevdebug-0.0.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3a140ef3ebe7cbc1d5ba01ba5590e60b66dcdc6ecc503446bac49b4a4fd2e86
|
|
| MD5 |
8f737f6aba00cad0806a6de3c2364376
|
|
| BLAKE2b-256 |
b90dba61db3d9a7333ffeca0d85a7348fb5f4f2fa04457746b21794b8a210dc3
|
File details
Details for the file clevdebug-0.0.2-py3-none-any.whl.
File metadata
- Download URL: clevdebug-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
595125b45721d781a1585f2cd964bb898422b30df0656b3b832d37e5c57178c0
|
|
| MD5 |
dae766710db65bdc90d6a958c626435c
|
|
| BLAKE2b-256 |
cdaffa74e3b01bc76271958737f738eb6e40eeb721031147abc4b352110c429a
|