Skip to content

Commit c162ddb

Browse files
committed
Make spath return list
1 parent 1cc7a2d commit c162ddb

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

philh_myftp_biz/functools/paths.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1+
from traceback import FrameSummary, extract_stack
2+
from types import FunctionType
3+
from os.path import basename
4+
15
def 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]

philh_myftp_biz/terminal/Log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)