Skip to content

Commit

Permalink
Merge pull request #160 from jorisvandenbossche/datadescriptor
Browse files Browse the repository at this point in the history
Use isdatadescriptor instead of isgetsetdescriptor
  • Loading branch information
rgommers committed Mar 30, 2018
2 parents d7a2bdc + 99cb0f3 commit 9ce2e69
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
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 @@ -241,7 +241,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]

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

0 comments on commit 9ce2e69

Please sign in to comment.