@@ -181,7 +181,14 @@ def _args_inspection_failed(self, args, kwargs):
181181
182182 def _process_args (self , func_ast , code_lines , args , kwargs ) -> Generator [DebugArgument , None , None ]: # noqa: C901
183183 arg_offsets = list (self ._get_offsets (func_ast ))
184- for arg , ast_node , i in zip (args , func_ast .args , range (1000 )):
184+ for i , arg in enumerate (args ):
185+ try :
186+ ast_node = func_ast .args [i ]
187+ except IndexError : # pragma: no cover
188+ # happens when code has been commented out and there are fewer func_ast args than real args
189+ yield self .output_class .arg_class (arg )
190+ continue
191+
185192 if isinstance (ast_node , ast .Name ):
186193 yield self .output_class .arg_class (arg , name = ast_node .id )
187194 elif isinstance (ast_node , self .complex_nodes ):
@@ -231,7 +238,7 @@ def _parse_code(
231238 tail_index = call_frame .index
232239 try :
233240 func_ast = self ._wrap_parse (code , filename )
234- except SyntaxError as e1 :
241+ except ( SyntaxError , AttributeError ) as e1 :
235242 # if the trailing bracket(s) of the function is/are on a new line eg.
236243 # debug(
237244 # foo, bar,
@@ -242,13 +249,13 @@ def _parse_code(
242249 code = dedent ('' .join (call_lines + extra_lines ))
243250 try :
244251 func_ast = self ._wrap_parse (code , filename )
245- except SyntaxError :
252+ except ( SyntaxError , AttributeError ) :
246253 pass
247254 else :
248255 break
249256
250257 if not func_ast :
251- return None , None , lineno , 'error passing code. Error : {}' .format (e1 )
258+ return None , None , lineno , 'error passing code, {0.__class__.__name__} : {0 }' .format (e1 )
252259
253260 if not isinstance (func_ast , ast .Call ):
254261 return None , None , lineno , 'error passing code, found {} not Call' .format (func_ast .__class__ )
@@ -277,7 +284,7 @@ def _get_offsets(func_ast):
277284 start_col -= 1
278285 yield start_line , start_col
279286 for kw in func_ast .keywords :
280- yield kw .value .lineno - 2 , kw .value .col_offset - len (kw .arg ) - 2
287+ yield kw .value .lineno - 2 , kw .value .col_offset - 2 - ( len (kw .arg ) if kw . arg else 0 )
281288
282289
283290debug = Debug ()
0 commit comments