[pypy-commit] pypy numpy-docstrings: Handle properties in add_docstring()

rlamy noreply at buildbot.pypy.org
Sat Jun 13 03:15:54 CEST 2015


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: numpy-docstrings
Changeset: r78073:8b8ecf5fd1ad
Date: 2015-06-13 01:43 +0100
http://bitbucket.org/pypy/pypy/changeset/8b8ecf5fd1ad/

Log:	Handle properties in add_docstring()

diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -5,6 +5,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import unwrap_spec, appdef
 from pypy.interpreter.function import Method
+from pypy.interpreter.typedef import GetSetProperty
 from pypy.objspace.std.typeobject import W_TypeObject
 
 def issequence_w(space, w_obj):
@@ -181,6 +182,10 @@
         if w_obj.w_doc is None or space.is_none(w_obj.w_doc):
             w_obj.w_doc = space.wrap(docstring)
             return
+    elif isinstance(w_obj, GetSetProperty):
+        if w_obj.doc is None or space.is_none(w_obj.doc):
+            w_obj.doc = space.wrap(docstring)
+            return
     _add_doc_w(space, w_obj, space.wrap(docstring))
 
 _add_doc_w = appdef("""add_docstring(obj, docstring):
diff --git a/pypy/module/micronumpy/test/test_support_app.py b/pypy/module/micronumpy/test/test_support_app.py
--- a/pypy/module/micronumpy/test/test_support_app.py
+++ b/pypy/module/micronumpy/test/test_support_app.py
@@ -20,3 +20,10 @@
         #raises(RuntimeError, np.add_docstring, int.bit_length, 'foo')
         np.add_docstring(int.bit_length,'foo')
         assert int.bit_length.__doc__ == 'foo'
+
+    def test_property_docstring(self):
+        # XXX: We cannot sensibly test np.add_docstring() being successful
+        import numpy as np
+        #raises(RuntimeError, np.add_docstring, int.bit_length, 'foo')
+        np.add_docstring(np.flatiter.base, 'foo')
+        assert np.flatiter.base.__doc__ == 'foo'


More information about the pypy-commit mailing list