File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -295,7 +295,17 @@ def source_file_def_line(self):
295
295
Number of line where the object is defined in its file.
296
296
"""
297
297
try :
298
- return inspect .getsourcelines (self .code_obj )[- 1 ]
298
+ sourcelines = inspect .getsourcelines (self .code_obj )
299
+ # getsourcelines will return the line of the first decorator found for the
300
+ # current function. We have to find the def declaration after that.
301
+ def_lines = [
302
+ i
303
+ for i , x in enumerate (
304
+ [re .match ("^ *(def|class)" , s ) for s in sourcelines [0 ]]
305
+ )
306
+ if x is not None
307
+ ]
308
+ return sourcelines [- 1 ] + def_lines [0 ]
299
309
except (OSError , TypeError ):
300
310
# In some cases the object is something complex like a cython
301
311
# object that can't be easily introspected. An it's better to
You can’t perform that action at this time.
0 commit comments