From: Jason Evans Date: Tue, 6 Jan 2009 01:19:39 +0000 (-0800) Subject: Take care to preserve cpdef method docstrings when prepending signatures. X-Git-Tag: 0.11-beta~26 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=30b562903f03feb0d436969521b39c4bb04a2d0b;p=cython.git Take care to preserve cpdef method docstrings when prepending signatures. --- diff --git a/Cython/Compiler/AutoDocTransforms.py b/Cython/Compiler/AutoDocTransforms.py index 1536af5c..4c26c2ba 100644 --- a/Cython/Compiler/AutoDocTransforms.py +++ b/Cython/Compiler/AutoDocTransforms.py @@ -135,7 +135,14 @@ class EmbedSignature(CythonTransform): doc_holder = self.class_node.entry.type.scope else: doc_holder = node.entry - new_doc = self._embed_signature(signature, doc_holder.doc) + + if doc_holder.doc is not None: + old_doc = doc_holder.doc + elif not is_constructor and getattr(node, 'py_func', None) is not None: + old_doc = node.py_func.entry.doc + else: + old_doc = None + new_doc = self._embed_signature(signature, old_doc) doc_holder.doc = EncodedString(new_doc) if not is_constructor and getattr(node, 'py_func', None) is not None: node.py_func.entry.doc = EncodedString(new_doc) @@ -152,7 +159,13 @@ class EmbedSignature(CythonTransform): node.declarator.args, return_type=node.return_type) if signature: - new_doc = self._embed_signature(signature, node.entry.doc) + if node.entry.doc is not None: + old_doc = node.entry.doc + elif hasattr(node, 'py_func') and node.py_func is not None: + old_doc = node.py_func.entry.doc + else: + old_doc = None + new_doc = self._embed_signature(signature, old_doc) node.entry.doc = EncodedString(new_doc) if hasattr(node, 'py_func') and node.py_func is not None: node.py_func.entry.doc = EncodedString(new_doc) diff --git a/tests/run/embedsignatures.pyx b/tests/run/embedsignatures.pyx index fbf694c2..f4c8d2a1 100644 --- a/tests/run/embedsignatures.pyx +++ b/tests/run/embedsignatures.pyx @@ -32,12 +32,20 @@ __doc__ = ur""" >>> print (Ext.k.__doc__) Ext.k(self, a, b, c=1, *args, d=42, e=17, f, **kwds) + >>> print (Ext.l.__doc__) + Ext.l(self, a, b, c=1, *args, d=42, e=17, f, **kwds) + Existing string + >>> print (Ext.get_int.__doc__) Ext.get_int(self) -> int >>> print (Ext.get_float.__doc__) Ext.get_float(self) -> float + >>> print (Ext.get_str.__doc__) + Ext.get_str(self) -> str + Existing string + >>> print (Ext.clone.__doc__) Ext.clone(self) -> Ext @@ -50,6 +58,12 @@ __doc__ = ur""" >>> with_doc_2.__doc__ 'with_doc_2(a, b, c)\n\n Existing string\n ' + >>> with_doc_3.__doc__ + 'with_doc_3(a, b, c)\nExisting string' + + >>> with_doc_4.__doc__ + 'with_doc_4(int a, str b, list c) -> str\n\n Existing string\n ' + >>> types.__doc__ 'types(Ext a, int b, unsigned short c, float d, e)' @@ -146,12 +160,20 @@ cdef class Ext: def k(self, a, b, c=1, *args, d = 42, e = 17, f, **kwds): pass + def l(self, a, b, c=1, *args, d = 42, e = 17, f, **kwds): + """Existing string""" + pass + cpdef int get_int(self): return 0 cpdef float get_float(self): return 0.0 + cpdef str get_str(self): + """Existing string""" + return "string" + cpdef Ext clone(self): return Ext(1,2) @@ -171,6 +193,16 @@ def with_doc_2(a, b, c): """ pass +cpdef with_doc_3(a, b, c): + """Existing string""" + pass + +cpdef str with_doc_4(int a, str b, list c): + """ + Existing string + """ + return b + cpdef char f_c(char c): return c