File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from traceback import FrameSummary , extract_stack
2+ from types import FunctionType
3+ from os .path import basename
4+
15def cpath (obj ) -> str :
26 """
37 Class Path
48
59 Ex: `cpath(print) -> '__builtins__.print'`
610 """
7- from types import FunctionType
8-
911 if not isinstance (obj , (type , FunctionType )):
1012 obj = obj .__class__
1113
1214 return obj .__module__ + '.' + obj .__qualname__
1315
14- def spath (x :int ) -> str :
16+ def strframe (frame : FrameSummary ) -> str :
17+ return f'{ basename (frame .filename )} :{ frame .lineno } '
18+
19+ def spath (
20+ x : int = 0 ,
21+ y : int = - 1
22+ ) -> list [str ]:
1523 """
1624 Stack Path
17-
18- Ex: `spath(0) -> 'test.py:14'`
25+ Ex: `spaths() -> ['test.py:14', ...]`
1926 """
20- from traceback import extract_stack
21- from os import path
2227
23- stack = filter (
28+ stack = list ( filter (
2429 lambda x : "<frozen " not in x .filename ,
2530 extract_stack ()
26- )
27-
28- frame = list (stack )[x ]
31+ )) [x :y ]
2932
30- return f' { path . basename ( frame . filename ) } : { frame . lineno } '
33+ return [ strframe ( f ) for f in stack ]
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ def decorator(f):
4040
4141 @wraps (f )
4242 def wrapper (* args , ** kwargs ):
43- logger (f"Calling ' { cpath (f )} @ { spath (0 ) } ' \n { args = } \n { kwargs = } " )
43+ logger (f"Calling { cpath (f )} \n { spath (0 , - 2 ) } \n { args = } \n { kwargs = } " )
4444 return f (* args , ** kwargs )
4545 return wrapper
4646
You can’t perform that action at this time.
0 commit comments