summaryrefslogtreecommitdiffstats
path: root/polymatrix/utils/getstacklines.py
diff options
context:
space:
mode:
Diffstat (limited to 'polymatrix/utils/getstacklines.py')
-rw-r--r--polymatrix/utils/getstacklines.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/polymatrix/utils/getstacklines.py b/polymatrix/utils/getstacklines.py
new file mode 100644
index 0000000..6fdd69f
--- /dev/null
+++ b/polymatrix/utils/getstacklines.py
@@ -0,0 +1,23 @@
+import dataclasses
+import traceback
+
+
+@dataclasses.dataclass(frozen=True)
+class FrameSummary:
+ filename: str
+ lineno: int
+ name: str
+ line: str
+
+
+def get_stack_lines(index: int = 2) -> tuple[FrameSummary]:
+ def gen_stack_lines():
+ for obj in traceback.extract_stack()[:-index]:
+ yield FrameSummary(
+ filename=obj.filename,
+ lineno=obj.lineno,
+ name=obj.name,
+ line=obj.line,
+ )
+
+ return tuple(gen_stack_lines())