File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ def find_first_executable_line(code):
118118    return  code .co_firstlineno 
119119
120120def  find_function (funcname , filename ):
121-     cre  =  re .compile (r'def\s+%s\s*[(]'  %  re .escape (funcname ))
121+     cre  =  re .compile (r'def\s+%s(\s*\[.+\])? \s*[(]'  %  re .escape (funcname ))
122122    try :
123123        fp  =  tokenize .open (filename )
124124    except  OSError :
@@ -138,7 +138,13 @@ def find_function(funcname, filename):
138138
139139            if  funcdef :
140140                try :
141-                     funccode  =  compile (funcdef , filename , 'exec' ).co_consts [0 ]
141+                     code  =  compile (funcdef , filename , 'exec' )
142+                     for  const  in  code .co_consts :
143+                         if  isinstance (const , CodeType ) and  const .co_name  ==  funcname :
144+                             funccode  =  const 
145+                             break 
146+                     else :
147+                         continue 
142148                except  SyntaxError :
143149                    continue 
144150                lineno_offset  =  find_first_executable_line (funccode )
Original file line number Diff line number Diff line change @@ -363,6 +363,42 @@ def test_pdb_breakpoint_commands():
363363    4 
364364    """ 
365365
366+ def  test_pdb_breakpoint_on_annotated_function_def ():
367+     """Test breakpoints on function definitions with annotation. 
368+ 
369+     >>> def foo[T](): 
370+     ...     return 0 
371+ 
372+     >>> def bar() -> int: 
373+     ...     return 0 
374+ 
375+     >>> def foobar[T]() -> int: 
376+     ...     return 0 
377+ 
378+     >>> reset_Breakpoint() 
379+ 
380+     >>> def test_function(): 
381+     ...     import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() 
382+     ...     pass 
383+ 
384+     >>> with PdbTestInput([  # doctest: +NORMALIZE_WHITESPACE 
385+     ...     'break foo', 
386+     ...     'break bar', 
387+     ...     'break foobar', 
388+     ...     'continue', 
389+     ... ]): 
390+     ...    test_function() 
391+     > <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[4]>(2)test_function() 
392+     -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() 
393+     (Pdb) break foo 
394+     Breakpoint 1 at <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[0]>:2 
395+     (Pdb) break bar 
396+     Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[1]>:2 
397+     (Pdb) break foobar 
398+     Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_on_annotated_function_def[2]>:2 
399+     (Pdb) continue 
400+     """ 
401+ 
366402def  test_pdb_commands ():
367403    """Test the commands command of pdb. 
368404
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments