Skip to content

Commit

Permalink
BUG: validator now handles decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
sdiebolt committed Aug 24, 2023
1 parent 6e748ef commit 6709682
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion numpydoc/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,17 @@ def source_file_def_line(self):
Number of line where the object is defined in its file.
"""
try:
return inspect.getsourcelines(self.code_obj)[-1]
sourcelines = inspect.getsourcelines(self.code_obj)
# getsourcelines will return the line of the first decorator found for the
# current function. We have to find the def declaration after that.
def_lines = [
i
for i, x in enumerate(
[re.match("^ *(def|class)", s) for s in sourcelines[0]]
)
if x is not None
]
return sourcelines[-1] + def_lines[0]
except (OSError, TypeError):
# In some cases the object is something complex like a cython
# object that can't be easily introspected. An it's better to
Expand Down

0 comments on commit 6709682

Please sign in to comment.