@@ -46,7 +46,7 @@ def str(self, highlight=False) -> str:
4646 suffix = sformat (
4747 ' ({.value.__class__.__name__}){}' .format (self , '' .join (' {}={}' .format (k , v ) for k , v in self .extra )),
4848 sformat .dim ,
49- apply = highlight
49+ apply = highlight ,
5050 )
5151 try :
5252 s += pformat (self .value , indent = 4 , highlight = highlight )
@@ -68,6 +68,7 @@ class DebugOutput:
6868 """
6969 Represents the output of a debug command.
7070 """
71+
7172 arg_class = DebugArgument
7273 __slots__ = 'filename' , 'lineno' , 'frame' , 'arguments' , 'warning'
7374
@@ -83,7 +84,7 @@ def str(self, highlight=False) -> str:
8384 prefix = '{}:{} {}' .format (
8485 sformat (self .filename , sformat .magenta ),
8586 sformat (self .lineno , sformat .green ),
86- sformat (self .frame , sformat .green , sformat .italic )
87+ sformat (self .frame , sformat .green , sformat .italic ),
8788 )
8889 if self .warning :
8990 prefix += sformat (' ({})' .format (self .warning ), sformat .dim )
@@ -104,15 +105,22 @@ def __repr__(self) -> str:
104105class Debug :
105106 output_class = DebugOutput
106107 complex_nodes = (
107- ast .Call , ast .Attribute , ast .Subscript ,
108- ast .IfExp , ast .BoolOp , ast .BinOp , ast .Compare ,
109- ast .DictComp , ast .ListComp , ast .SetComp , ast .GeneratorExp
108+ ast .Call ,
109+ ast .Attribute ,
110+ ast .Subscript ,
111+ ast .IfExp ,
112+ ast .BoolOp ,
113+ ast .BinOp ,
114+ ast .Compare ,
115+ ast .DictComp ,
116+ ast .ListComp ,
117+ ast .SetComp ,
118+ ast .GeneratorExp ,
110119 )
111120
112- def __init__ (self , * ,
113- warnings : Optional [bool ] = None ,
114- highlight : Optional [bool ] = None ,
115- frame_context_length : int = 50 ):
121+ def __init__ (
122+ self , * , warnings : Optional [bool ] = None , highlight : Optional [bool ] = None , frame_context_length : int = 50
123+ ):
116124 self ._show_warnings = self ._env_bool (warnings , 'PY_DEVTOOLS_WARNINGS' , True )
117125 self ._highlight = self ._env_bool (highlight , 'PY_DEVTOOLS_HIGHLIGHT' , None )
118126 # 50 lines should be enough to make sure we always get the entire function definition
@@ -217,9 +225,7 @@ def _process_args(self, func_ast, code_lines, args, kwargs) -> Generator[DebugAr
217225 for l_ in range (start_line , end_line + 1 ):
218226 start_ = start_col if l_ == start_line else 0
219227 end_ = end_col if l_ == end_line else None
220- name_lines .append (
221- code_lines [l_ ][start_ :end_ ].strip (' ' )
222- )
228+ name_lines .append (code_lines [l_ ][start_ :end_ ].strip (' ' ))
223229 yield self .output_class .arg_class (arg , name = ' ' .join (name_lines ).strip (' ,' ))
224230 else :
225231 yield self .output_class .arg_class (arg )
@@ -239,7 +245,7 @@ def _parse_code(
239245 try :
240246 new_line = call_frame .code_context [line ]
241247 except IndexError : # pragma: no cover
242- return None , None , line , 'error passing code. line not found'
248+ return None , None , line , 'error parsing code. line not found'
243249 call_lines .append (new_line )
244250 if re .search (func_regex , new_line ):
245251 break
@@ -258,7 +264,7 @@ def _parse_code(
258264 # )
259265 # inspect ignores it when setting index and we have to add it back
260266 for extra in range (2 , 6 ):
261- extra_lines = call_frame .code_context [tail_index + 1 : tail_index + extra ]
267+ extra_lines = call_frame .code_context [tail_index + 1 : tail_index + extra ]
262268 code = dedent ('' .join (call_lines + extra_lines ))
263269 try :
264270 func_ast = self ._wrap_parse (code , filename )
@@ -268,12 +274,12 @@ def _parse_code(
268274 break
269275
270276 if not func_ast :
271- return None , None , lineno , 'error passing code, {0.__class__.__name__}: {0}' .format (e1 )
277+ return None , None , lineno , 'error parsing code, {0.__class__.__name__}: {0}' .format (e1 )
272278
273279 if not isinstance (func_ast , ast .Call ):
274- return None , None , lineno , 'error passing code, found {} not Call' .format (func_ast .__class__ )
280+ return None , None , lineno , 'error parsing code, found {} not Call' .format (func_ast .__class__ )
275281
276- code_lines = [l for l in code .split ('\n ' ) if l ]
282+ code_lines = [line for line in code .split ('\n ' ) if line ]
277283 # this removes the trailing bracket from the lines of code meaning it doesn't appear in the
278284 # representation of the last argument
279285 code_lines [- 1 ] = code_lines [- 1 ][:- 1 ]
0 commit comments