diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index 6ca62922..598b4438 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -613,7 +613,7 @@ def properties(self): return [name for name, func in inspect.getmembers(self._cls) if (not name.startswith('_') and (func is None or isinstance(func, property) or - inspect.isgetsetdescriptor(func)) + inspect.isdatadescriptor(func)) and self._is_show_member(name))] def _is_show_member(self, name): diff --git a/numpydoc/docscrape_sphinx.py b/numpydoc/docscrape_sphinx.py index 087ddafb..e1135a55 100644 --- a/numpydoc/docscrape_sphinx.py +++ b/numpydoc/docscrape_sphinx.py @@ -242,7 +242,7 @@ def _str_member_list(self, name): param_obj = getattr(self._obj, param, None) if not (callable(param_obj) or isinstance(param_obj, property) - or inspect.isgetsetdescriptor(param_obj)): + or inspect.isdatadescriptor(param_obj)): param_obj = None if param_obj and pydoc.getdoc(param_obj): diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index 2fb4eb5a..285afbc4 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -15,7 +15,7 @@ ParseError ) from numpydoc.docscrape_sphinx import (SphinxDocString, SphinxClassDoc, - SphinxFunctionDoc) + SphinxFunctionDoc, get_doc_object) from nose.tools import (assert_equal, assert_raises, assert_list_equal, assert_true) @@ -1199,6 +1199,33 @@ def test_templated_sections(): """) +def test_nonstandard_property(): + # test discovery of a property that does not satisfy isinstace(.., property) + + class SpecialProperty(object): + + def __init__(self, axis=0, doc=""): + self.axis = axis + self.__doc__ = doc + + def __get__(self, obj, type): + if obj is None: + # Only instances have actual _data, not classes + return self + else: + return obj._data.axes[self.axis] + + def __set__(self, obj, value): + obj._set_axis(self.axis, value) + + class Dummy: + + attr = SpecialProperty(doc="test attribute") + + doc = get_doc_object(Dummy) + assert "test attribute" in str(doc) + + if __name__ == "__main__": import nose nose.run()