Skip to content

Commit 6709682

Browse files
committed
BUG: validator now handles decorators
1 parent 6e748ef commit 6709682

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

numpydoc/validate.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,17 @@ def source_file_def_line(self):
295295
Number of line where the object is defined in its file.
296296
"""
297297
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]
299309
except (OSError, TypeError):
300310
# In some cases the object is something complex like a cython
301311
# object that can't be easily introspected. An it's better to

0 commit comments

Comments
 (0)