From 15cfb04050b3297bedd0c4110be63be5bf8c7d52 Mon Sep 17 00:00:00 2001 From: Nathan Abel Date: Tue, 15 Oct 2019 16:46:28 -0400 Subject: [PATCH 1/2] Replace with inspect.unwrap Replaced the function to_original_callable with the function inspect.unwrap --- scripts/validate_docstrings.py | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 1d0f4b583bd0c..5b51449a790a6 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -245,7 +245,7 @@ def __init__(self, name): self.name = name obj = self._load_obj(name) self.obj = obj - self.code_obj = self._to_original_callable(obj) + self.code_obj = inspect.unwrap(obj) self.raw_doc = obj.__doc__ or "" self.clean_doc = pydoc.getdoc(obj) self.doc = NumpyDocString(self.clean_doc) @@ -292,30 +292,6 @@ def _load_obj(name): obj = getattr(obj, part) return obj - @staticmethod - def _to_original_callable(obj): - """ - Find the Python object that contains the source code of the object. - - This is useful to find the place in the source code (file and line - number) where a docstring is defined. It does not currently work for - all cases, but it should help find some (properties...). - """ - while True: - if inspect.isfunction(obj) or inspect.isclass(obj): - f = inspect.getfile(obj) - if f.startswith("<") and f.endswith(">"): - return None - return obj - if inspect.ismethod(obj): - obj = obj.__func__ - elif isinstance(obj, functools.partial): - obj = obj.func - elif isinstance(obj, property): - obj = obj.fget - else: - return None - @property def type(self): return type(self.obj).__name__ From 4a1d9d829b567400480efaec36de08839ab0100e Mon Sep 17 00:00:00 2001 From: Nathan Abel Date: Tue, 15 Oct 2019 22:07:52 -0400 Subject: [PATCH 2/2] CLN: Remove functools import This import is now unnecessary for this script. --- scripts/validate_docstrings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 5b51449a790a6..95f3392011d3f 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -17,7 +17,6 @@ import ast import collections import doctest -import functools import glob import importlib import inspect