We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6e748ef commit 6709682Copy full SHA for 6709682
numpydoc/validate.py
@@ -295,7 +295,17 @@ def source_file_def_line(self):
295
Number of line where the object is defined in its file.
296
"""
297
try:
298
- return inspect.getsourcelines(self.code_obj)[-1]
+ 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]
309
except (OSError, TypeError):
310
# In some cases the object is something complex like a cython
311
# object that can't be easily introspected. An it's better to
0 commit comments