Convenience functions for the python execution stack.
Project description
I find the supplied python traceback facilities quite awkward. These functions provide convenient facilities.
Latest release 20250724: frames: tweak the exception frame access.
Short summary:
caller: Return theFrameof the caller's caller. ReturnsNoneifframe_indexis out of range.frames: Return the current stack as aStackSummaryinstance, a list ofFrameSummaryinstances.stack_dump: Recite current or supplied stack tof, defaultsys.stderr.
Module contents:
-
caller(frame_index=-3): Return theFrameof the caller's caller. ReturnsNoneifframe_indexis out of range.Useful
frame_indexvalues:-1: caller, this function-2: invoker, who wants to know the caller-3: the calling function of the invoker
The default
from_indexvalue is-3. -
frames(source=None, limit=None): Return the current stack as aStackSummaryinstance, a list ofFrameSummaryinstances. Crop the returned list atlimitif it is notNone.If
sourceis omitted orNone, obtain the source stack fromtraceback.extract_stack(). Otherwise ifsourcehas a.tb_frameattribute (like atracebackobject) orsourcehas a.__traceback__attribute (like an exception), calltraceback.extract_stackwith that to obtain the source stack. -
stack_dump(f=None, indent=0, summary=None, skip=None, select=None, format_frame=None): Recite current or supplied stack tof, defaultsys.stderr.Parameters:
f: the output file object, defaultsys.stderrindent: how many spaces to indent the stack lines, default0summary: the stackFrames to write, default obtained from the current stackskip: the number ofFrames to trim from the end ofsummary; ifsummaryisNonethis defaults to2to trim theFrames for thestack_dumpfunction and its call toframes(), otherwise the default is0to use the suppliedFrames as isselect: if notNone, select particular frames; ifselectis astrit must be present in the frame filename; otherwiseselect(frame)must be true
Release Log
Release 20250724: frames: tweak the exception frame access.
Release 20250306: frame: accept an optional traceback object or exception as a source from which to obtain the stack, add optional limit to crop the stack.
Release 20240630:
- The fallback StackSummary: add format_frame_summary(frame) static method.
- stack_dump: updates to avoid a name conflict, expect to work off a StackSummary or a list of frames.
Release 20240519: Drop Frame.funcname property.
Release 20240412:
- stack_dump: new select parameter to pick interesting frames for the listing.
- Provide StackSummary and FrameSummary if Python too old.
Release 20220918: caller(): return None if the frame offset is out of range.
Release 20220429: caller: return None if the stack index is out of range.
Release 20190812: stack_dump(): trim the last 2 frames from the listing by default (they are part of stack_dump's implementation).
Release 20190101:
- _Frame: rename .functionname to .funcname; caller: turn raw frames into Frames.
- caller(): accept optional frame_index, default -3.
Release 20160827: Add stack_dump().
Release 20150115: PyPI metadata fixups.
Release 20150111: Tag for initial PyPI release of cs.py.stack.
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
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 cs_py_stack-20250724.tar.gz.
File metadata
- Download URL: cs_py_stack-20250724.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8cf24189ecb0e8075a6b04215c95c15b473077199f8085f095bbf2aae1a3b86
|
|
| MD5 |
33d91bd443a7fb6b8861beeb6a272172
|
|
| BLAKE2b-256 |
01a86df6c20efef088319e316e014d188dde6cfc51ea851db7a96cee3527da03
|
File details
Details for the file cs_py_stack-20250724-py2.py3-none-any.whl.
File metadata
- Download URL: cs_py_stack-20250724-py2.py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf40ccd28c527d27742f2e2f7ae2cf9574cdc39daecc325b3ed2197abde1e77
|
|
| MD5 |
c53d469eeb4892d1a11f024329c2094f
|
|
| BLAKE2b-256 |
c79affdb7ea61137099ffa316462387fd0d0cdbfcbe07751e752d27ab043a767
|