Skip to content

Use isdatadescriptor instead of isgetsetdescriptor #160

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

Merged
merged 2 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion numpydoc/docscrape_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 28 additions & 1 deletion numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test case.
The line above is from our original example in pandas, and actually does not matter (it's the if obj is None: return self that matters, so I can also remove this


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()