Skip to content

Commit 9ce2e69

Browse files
authored
Merge pull request #160 from jorisvandenbossche/datadescriptor
Use isdatadescriptor instead of isgetsetdescriptor
2 parents d7a2bdc + 99cb0f3 commit 9ce2e69

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

numpydoc/docscrape.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def properties(self):
613613
return [name for name, func in inspect.getmembers(self._cls)
614614
if (not name.startswith('_') and
615615
(func is None or isinstance(func, property) or
616-
inspect.isgetsetdescriptor(func))
616+
inspect.isdatadescriptor(func))
617617
and self._is_show_member(name))]
618618

619619
def _is_show_member(self, name):

numpydoc/docscrape_sphinx.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def _str_member_list(self, name):
241241
param_obj = getattr(self._obj, param, None)
242242
if not (callable(param_obj)
243243
or isinstance(param_obj, property)
244-
or inspect.isgetsetdescriptor(param_obj)):
244+
or inspect.isdatadescriptor(param_obj)):
245245
param_obj = None
246246

247247
if param_obj and pydoc.getdoc(param_obj):

numpydoc/tests/test_docscrape.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ParseError
1616
)
1717
from numpydoc.docscrape_sphinx import (SphinxDocString, SphinxClassDoc,
18-
SphinxFunctionDoc)
18+
SphinxFunctionDoc, get_doc_object)
1919
from nose.tools import (assert_equal, assert_raises, assert_list_equal,
2020
assert_true)
2121

@@ -1199,6 +1199,33 @@ def test_templated_sections():
11991199
""")
12001200

12011201

1202+
def test_nonstandard_property():
1203+
# test discovery of a property that does not satisfy isinstace(.., property)
1204+
1205+
class SpecialProperty(object):
1206+
1207+
def __init__(self, axis=0, doc=""):
1208+
self.axis = axis
1209+
self.__doc__ = doc
1210+
1211+
def __get__(self, obj, type):
1212+
if obj is None:
1213+
# Only instances have actual _data, not classes
1214+
return self
1215+
else:
1216+
return obj._data.axes[self.axis]
1217+
1218+
def __set__(self, obj, value):
1219+
obj._set_axis(self.axis, value)
1220+
1221+
class Dummy:
1222+
1223+
attr = SpecialProperty(doc="test attribute")
1224+
1225+
doc = get_doc_object(Dummy)
1226+
assert "test attribute" in str(doc)
1227+
1228+
12021229
if __name__ == "__main__":
12031230
import nose
12041231
nose.run()

0 commit comments

Comments
 (0)