cython-devel
changeset 1608:4486c09becf3
Take care to preserve cpdef method docstrings when prepending signatures.
| author | Jason Evans <jasone@canonware.com> |
|---|---|
| date | Mon Jan 05 17:19:39 2009 -0800 (4 years ago) |
| parents | a9a564f13da9 |
| children | f51f733b41b8 |
| files | Cython/Compiler/AutoDocTransforms.py tests/run/embedsignatures.pyx |
line diff
1.1 --- a/Cython/Compiler/AutoDocTransforms.py Mon Jan 12 16:30:03 2009 +0100
1.2 +++ b/Cython/Compiler/AutoDocTransforms.py Mon Jan 05 17:19:39 2009 -0800
1.3 @@ -135,7 +135,14 @@
1.4 doc_holder = self.class_node.entry.type.scope
1.5 else:
1.6 doc_holder = node.entry
1.7 - new_doc = self._embed_signature(signature, doc_holder.doc)
1.8 +
1.9 + if doc_holder.doc is not None:
1.10 + old_doc = doc_holder.doc
1.11 + elif not is_constructor and getattr(node, 'py_func', None) is not None:
1.12 + old_doc = node.py_func.entry.doc
1.13 + else:
1.14 + old_doc = None
1.15 + new_doc = self._embed_signature(signature, old_doc)
1.16 doc_holder.doc = EncodedString(new_doc)
1.17 if not is_constructor and getattr(node, 'py_func', None) is not None:
1.18 node.py_func.entry.doc = EncodedString(new_doc)
1.19 @@ -152,7 +159,13 @@
1.20 node.declarator.args,
1.21 return_type=node.return_type)
1.22 if signature:
1.23 - new_doc = self._embed_signature(signature, node.entry.doc)
1.24 + if node.entry.doc is not None:
1.25 + old_doc = node.entry.doc
1.26 + elif hasattr(node, 'py_func') and node.py_func is not None:
1.27 + old_doc = node.py_func.entry.doc
1.28 + else:
1.29 + old_doc = None
1.30 + new_doc = self._embed_signature(signature, old_doc)
1.31 node.entry.doc = EncodedString(new_doc)
1.32 if hasattr(node, 'py_func') and node.py_func is not None:
1.33 node.py_func.entry.doc = EncodedString(new_doc)
2.1 --- a/tests/run/embedsignatures.pyx Mon Jan 12 16:30:03 2009 +0100
2.2 +++ b/tests/run/embedsignatures.pyx Mon Jan 05 17:19:39 2009 -0800
2.3 @@ -32,12 +32,20 @@
2.4 >>> print (Ext.k.__doc__)
2.5 Ext.k(self, a, b, c=1, *args, d=42, e=17, f, **kwds)
2.6
2.7 + >>> print (Ext.l.__doc__)
2.8 + Ext.l(self, a, b, c=1, *args, d=42, e=17, f, **kwds)
2.9 + Existing string
2.10 +
2.11 >>> print (Ext.get_int.__doc__)
2.12 Ext.get_int(self) -> int
2.13
2.14 >>> print (Ext.get_float.__doc__)
2.15 Ext.get_float(self) -> float
2.16
2.17 + >>> print (Ext.get_str.__doc__)
2.18 + Ext.get_str(self) -> str
2.19 + Existing string
2.20 +
2.21 >>> print (Ext.clone.__doc__)
2.22 Ext.clone(self) -> Ext
2.23
2.24 @@ -50,6 +58,12 @@
2.25 >>> with_doc_2.__doc__
2.26 'with_doc_2(a, b, c)\n\n Existing string\n '
2.27
2.28 + >>> with_doc_3.__doc__
2.29 + 'with_doc_3(a, b, c)\nExisting string'
2.30 +
2.31 + >>> with_doc_4.__doc__
2.32 + 'with_doc_4(int a, str b, list c) -> str\n\n Existing string\n '
2.33 +
2.34 >>> types.__doc__
2.35 'types(Ext a, int b, unsigned short c, float d, e)'
2.36
2.37 @@ -146,12 +160,20 @@
2.38 def k(self, a, b, c=1, *args, d = 42, e = 17, f, **kwds):
2.39 pass
2.40
2.41 + def l(self, a, b, c=1, *args, d = 42, e = 17, f, **kwds):
2.42 + """Existing string"""
2.43 + pass
2.44 +
2.45 cpdef int get_int(self):
2.46 return 0
2.47
2.48 cpdef float get_float(self):
2.49 return 0.0
2.50
2.51 + cpdef str get_str(self):
2.52 + """Existing string"""
2.53 + return "string"
2.54 +
2.55 cpdef Ext clone(self):
2.56 return Ext(1,2)
2.57
2.58 @@ -171,6 +193,16 @@
2.59 """
2.60 pass
2.61
2.62 +cpdef with_doc_3(a, b, c):
2.63 + """Existing string"""
2.64 + pass
2.65 +
2.66 +cpdef str with_doc_4(int a, str b, list c):
2.67 + """
2.68 + Existing string
2.69 + """
2.70 + return b
2.71 +
2.72 cpdef char f_c(char c):
2.73 return c
2.74
