File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from inspect import getframeinfo
44from types import FrameType , TracebackType
55
6- TB_ENV_KEY_NAME = "SPY_SHOW_MAGIC_FRAMES"
7-
86
97def _is_magic_dispatch_frame (f : FrameType ) -> bool :
108 info = getframeinfo (f )
119 return "util.py" in info .filename and info .function == "magic_dispatch"
1210
1311
1412def _is_magic_dispatch_call (f : FrameType ) -> bool :
13+ """
14+ Check whether the string `magic_dispatch(` is in the line of code that's
15+ present the current frame of a traceback. info.code_context is an array of
16+ strings of the lines of code "around" the line being executed.
17+ info.index is the index of the line currently being executed
18+ """
1519 info = getframeinfo (f )
1620 return (context := info .code_context ) is not None and "magic_dispatch(" in context [
17- 0
21+ info . index
1822 ]
1923
2024
@@ -27,7 +31,7 @@ def tb_hide_magic_frames_maybe() -> TracebackType:
2731 assert head_tb is not None
2832 tb = head_tb
2933
30- if (env_val := os .getenv (TB_ENV_KEY_NAME )) and int (env_val ) == 1 :
34+ if (env_val := os .getenv ("SPY_SHOW_MAGIC_FRAMES" )) and int (env_val ) == 1 :
3135 # We actually want to show all the magic frames; return stack unchanged
3236 pass
3337 else :
@@ -43,7 +47,7 @@ def tb_hide_magic_frames_maybe() -> TracebackType:
4347 else :
4448 assert (
4549 tb .tb_next is not None
46- ) # make mypy happy; we know this is try from the while statement above
50+ ) # make mypy happy; we know this is true from the while statement above
4751 tb = tb .tb_next
4852
4953 return head_tb
You can’t perform that action at this time.
0 commit comments