@@ -112,8 +112,15 @@ def __init__(self, *, warnings: 'Optional[bool]' = None, highlight: 'Optional[bo
112
112
self ._show_warnings = env_bool (warnings , 'PY_DEVTOOLS_WARNINGS' , True )
113
113
self ._highlight = highlight
114
114
115
- def __call__ (self , * args : 'Any' , file_ : 'Any' = None , flush_ : bool = True , ** kwargs : 'Any' ) -> 'Any' :
116
- d_out = self ._process (args , kwargs )
115
+ def __call__ (
116
+ self ,
117
+ * args : 'Any' ,
118
+ file_ : 'Any' = None ,
119
+ flush_ : bool = True ,
120
+ frame_depth_ : int = 2 ,
121
+ ** kwargs : 'Any' ,
122
+ ) -> 'Any' :
123
+ d_out = self ._process (args , kwargs , frame_depth_ )
117
124
s = d_out .str (use_highlight (self ._highlight , file_ ))
118
125
print (s , file = file_ , flush = flush_ )
119
126
if kwargs :
@@ -123,8 +130,8 @@ def __call__(self, *args: 'Any', file_: 'Any' = None, flush_: bool = True, **kwa
123
130
else :
124
131
return args
125
132
126
- def format (self , * args : 'Any' , ** kwargs : 'Any' ) -> DebugOutput :
127
- return self ._process (args , kwargs )
133
+ def format (self , * args : 'Any' , frame_depth_ : int = 2 , ** kwargs : 'Any' ) -> DebugOutput :
134
+ return self ._process (args , kwargs , frame_depth_ )
128
135
129
136
def breakpoint (self ) -> None :
130
137
import pdb
@@ -134,13 +141,13 @@ def breakpoint(self) -> None:
134
141
def timer (self , name : 'Optional[str]' = None , * , verbose : bool = True , file : 'Any' = None , dp : int = 3 ) -> Timer :
135
142
return Timer (name = name , verbose = verbose , file = file , dp = dp )
136
143
137
- def _process (self , args : 'Any' , kwargs : 'Any' ) -> DebugOutput :
144
+ def _process (self , args : 'Any' , kwargs : 'Any' , frame_depth : int ) -> DebugOutput :
138
145
"""
139
- BEWARE: this must be called from a function exactly 2 levels below the top of the stack.
146
+ BEWARE: this must be called from a function exactly `frame_depth` levels below the top of the stack.
140
147
"""
141
148
# HELP: any errors other than ValueError from _getframe? If so please submit an issue
142
149
try :
143
- call_frame : 'FrameType' = sys ._getframe (2 )
150
+ call_frame : 'FrameType' = sys ._getframe (frame_depth )
144
151
except ValueError :
145
152
# "If [ValueError] is deeper than the call stack, ValueError is raised"
146
153
return self .output_class (
0 commit comments