Skip to content

Remove to original callable #29012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

27 changes: 1 addition & 26 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ast
import collections
import doctest
import functools
import glob
import importlib
import inspect
Expand Down Expand Up @@ -245,7 +244,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)
Expand Down Expand Up @@ -292,30 +291,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__
Expand Down