11import functools
22import time
33from tkinter import Event
4-
4+ from . base import *
55from .console import getPPrintStr , pp
66
77
88
9-
109__all__ = ['debug' , 'class_method_debug' , 'check_time' , 'debugTkinterEvent' , 'pprint_debug' ]
1110
12- DEFAULT_TAG = '\n ______________________________________________________________\n "{0}"'
13-
14- def GetFuncModule (func : callable ) -> str :
15- return func .__module__
16- def GetFunctionName (func : callable ) -> str :
17- if hasattr (func , '__qualname__' ):
18- return func .__qualname__
19- elif hasattr (func , '__module__' ):
20- return f"{ func .__module__ } .{ func .__qualname__ } "
21- else :
22- return func .__name__
23-
24-
25-
26- def _print_signature (func , tag , * args , ** kwargs ):
27- name = GetFunctionName (func )
28- print (tag .format (f'{ name } ' ))
29-
30- if args or kwargs :
31- try : args_repr = [repr (a ) for a in args ] # 1
32- except : args_repr = [str (a ) for a in args ] # 1
33-
34- kwargs_repr = [f"{ k } ={ v !r} " for k , v in kwargs .items ()] # 2
35-
36- signature = ", " .join (args_repr + kwargs_repr ) # 3
37-
38- print (f"{ name } (\n { signature } \n )" )
39-
4011
4112def class_method_debug (cls : str or type , tag : str = DEFAULT_TAG ):
4213 """
@@ -57,6 +28,7 @@ def debug_inner(func: callable = None):
5728 :return:
5829 """
5930 name = f"{ cls } .{ func .__name__ } "
31+
6032 @functools .wraps (func )
6133 def wrapper_debug (* args , ** kwargs ):
6234 print (tag .format (name ))
@@ -87,9 +59,10 @@ def debug(func: callable, tag: str = DEFAULT_TAG):
8759 :return:
8860 """
8961 name = GetFunctionName (func )
62+
9063 @functools .wraps (func )
9164 def wrapper_debug (* args , ** kwargs ):
92- _print_signature (func , tag , * args , ** kwargs )
65+ print_signature (func , tag , * args , ** kwargs )
9366 result = func (* args , ** kwargs )
9467 print (f"{ name } returned { result !r} \n " ) # 4
9568
@@ -107,6 +80,7 @@ def pprint_debug(func: callable, tag: str = DEFAULT_TAG):
10780 :return:
10881 """
10982 name = GetFunctionName (func )
83+
11084 @functools .wraps (func )
11185 def wrapper_debug (* args , ** kwargs ):
11286 print (tag .format (name ))
@@ -134,6 +108,7 @@ def check_cls_time(*, cls: str or type = None, print_signature: bool = True, tag
134108
135109 def timeit (func : callable ):
136110 name = GetFunctionName (func )
111+
137112 @functools .wraps (func )
138113 def timed (* args , ** kwargs ):
139114 print (tag .format (name ))
@@ -163,9 +138,10 @@ def timed(*args, **kwargs):
163138
164139def check_time (func : callable , tag : str = DEFAULT_TAG ):
165140 name = GetFunctionName (func )
141+
166142 @functools .wraps (func )
167143 def timed (* args , ** kwargs ):
168- _print_signature (func , tag , * args , ** kwargs )
144+ print_signature (func , tag , * args , ** kwargs )
169145
170146 start_time = time .time ()
171147 result = func (* args , ** kwargs )
@@ -179,6 +155,7 @@ def timed(*args, **kwargs):
179155
180156def debugTkinterEvent (func : callable , tag : str = DEFAULT_TAG ):
181157 name = GetFunctionName (func )
158+
182159 @functools .wraps (func )
183160 def wrapper_debug (self , event : Event , * args , ** kwargs ):
184161 print (tag .format (f'{ name } ' ))
0 commit comments