From 6709682cd1c9ec665df86ba179862ee305d5bcfc Mon Sep 17 00:00:00 2001 From: sdiebolt Date: Thu, 24 Aug 2023 11:53:37 +0200 Subject: [PATCH] BUG: validator now handles decorators --- numpydoc/validate.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/numpydoc/validate.py b/numpydoc/validate.py index 922f817f..7cd37341 100644 --- a/numpydoc/validate.py +++ b/numpydoc/validate.py @@ -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