OK, Dag. For the moment, apply the attached patch. If fix the
rendering of basic C type modifiers in argument lists and return type
of cpdef functions. I'll take a look next week on the new way you are
suggesting.

BTW, the Epydoc monkeypatching in Tools/cython-epydoc.py is really
naive. I'm not good at writing regular expresions. That tool needs a
better regex for argument lists, at least if we want Epydoc still be
able to parse the format in core Python builtin functions/methods.


On Fri, Sep 19, 2008 at 1:10 PM, Dag Sverre Seljebotn
<[EMAIL PROTECTED]> wrote:
> Have some time for more details while waiting for my bus...:
>
> - When moving the transform to after AnalyseDeclarations, you must modify 
> funcnode.py_func.doc as well as funcnode.doc for "cpdef" functions.
>
> - Rather than inspecting the syntax  tree nodes for the arguments, 
> funcnode.local_scope.arg_entries can be iterated. It contains a quite clean 
> view of the arguments (should lean to fewer special cases in your code).
>
> Got to go.
>
> Dag Sverre Seljebotn
> -----Original Message-----
> From: Dag Sverre Seljebotn <[EMAIL PROTECTED]>
> Date: Friday, Sep 19, 2008 5:33 pm
> Subject: Re: [Cython] PATCH: embed signatures
> To: [EMAIL PROTECTED]: [email protected]
>
> Lisandro Dalcin wrote:
>> On Fri, Sep 19, 2008 at 11:34 AM, Dag Sverre Seljebotn
>> <[EMAIL PROTECTED]> wrote:
>>
>>>
>>> I didn't close the ticket though as
>>>
>>> def f(unsigned short i): pass
>>>
>>> ...will get "int" as the description.
>>>
>>
>>> Ups! My fault, I'm working right now in a fix for this....
>>
>>Please have a look at PyrexTypes.py first though, and make sure that you
>>don't duplicate code -- I think there's already code for making Cython
>>representations of types. (However you need to move your transform to
>>after AnalyseDeclarations and inspect funcnode.local_scope.arg_entries
>>to access the type objects)
>>
>>Dag Sverre
>>_______________________________________________
>>Cython-dev mailing list
>>[email protected]
>>http://codespeak.net/mailman/listinfo/cython-dev
>>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
diff -r 137cca05a493 Cython/Compiler/AutoDocTransforms.py
--- a/Cython/Compiler/AutoDocTransforms.py	Fri Sep 19 16:38:34 2008 +0200
+++ b/Cython/Compiler/AutoDocTransforms.py	Fri Sep 19 13:56:06 2008 -0300
@@ -17,11 +17,31 @@ class EmbedSignature(CythonTransform):
         self.is_in_class = False
         self.class_name = None
 
+    def _fmt_basic_c_type_modifiers(self, ctype):
+        longness = ctype.longness
+        modifiers = ''
+        if longness < 0:
+            modifiers = 'short '
+        elif longness > 0:
+            modifiers = 'long ' * longness
+        signed = ctype.signed
+        if signed == 0:
+            modifiers = 'unsigned ' + modifiers
+        elif signed == 2:
+            modifiers = 'signed ' + modifiers
+        return modifiers[:-1] # strip final space
+
     def _fmt_arg_type(self, arg):
         try:
-            return arg.base_type.name
+            base_type = arg.base_type
+            arg_type = base_type.name
         except AttributeError:
-            return ""
+            return ''
+        if base_type.is_basic_c_type:
+            modifiers = self._fmt_basic_c_type_modifiers(base_type)
+            if modifiers:
+                arg_type = '%s %s' % (modifiers, arg_type)
+        return arg_type
 
     def _fmt_arg_name(self, arg):
         try:
@@ -68,6 +88,15 @@ class EmbedSignature(CythonTransform):
             arglist.append('**%s' % kargs.name)
         return arglist
 
+    def _fmt_ret_type(self, ret):
+        ret_type = ret.name
+        if ret_type is None:
+            return ''
+        modifiers = self._fmt_basic_c_type_modifiers(ret)
+        if modifiers:
+            ret_type = '%s %s' % (modifiers, ret_type)
+        return ret_type
+
     def _fmt_signature(self, cls_name, func_name, args,
                        npargs=0, pargs=None,
                        nkargs=0, kargs=None,
@@ -75,12 +104,14 @@ class EmbedSignature(CythonTransform):
         arglist = self._fmt_arglist(args,
                                     npargs, pargs,
                                     nkargs, kargs)
-        arglist = ', '.join(arglist)
-        func_doc = '%s(%s)' % (func_name, arglist)
+        arglist_doc = ', '.join(arglist)
+        func_doc = '%s(%s)' % (func_name, arglist_doc)
         if cls_name:
-            func_doc = ('%s.' % cls_name) + func_doc
+            func_doc = '%s.%s' % (cls_name, func_doc)
         if return_type:
-            func_doc = func_doc + ' -> %s' % return_type
+            ret_doc = self._fmt_ret_type(return_type)
+            if ret_doc:
+                func_doc = '%s -> %s' % (func_doc, ret_doc)
         return func_doc
 
     def _embed_signature(self, signature, node_doc):
@@ -133,7 +164,7 @@ class EmbedSignature(CythonTransform):
                 signature = self._fmt_signature(
                     self.class_name, node.declarator.base.name,
                     node.declarator.args,
-                    return_type=node.base_type.name)
+                    return_type=node.base_type)
         else: # should not fall here ...
             assert False
         if signature:
diff -r 137cca05a493 tests/run/embedsignatures2.pyx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/run/embedsignatures2.pyx	Fri Sep 19 13:49:43 2008 -0300
@@ -0,0 +1,122 @@
+#cython: embedsignature=True
+
+__doc__ = u"""
+    >>> print (f_c.__doc__)
+    f_c(char c) -> char
+
+    >>> print (f_uc.__doc__)
+    f_uc(unsigned char c) -> unsigned char
+
+    >>> print (f_sc.__doc__)
+    f_sc(signed char c) -> signed char
+
+
+    >>> print (f_s.__doc__)
+    f_s(short int s) -> short int
+
+    >>> print (f_us.__doc__)
+    f_us(unsigned short int s) -> unsigned short int
+
+    >>> print (f_ss.__doc__)
+    f_ss(signed short int s) -> signed short int
+
+
+    >>> print (f_i.__doc__)
+    f_i(int i) -> int
+
+    >>> print (f_ui.__doc__)
+    f_ui(unsigned int i) -> unsigned int
+
+    >>> print (f_si.__doc__)
+    f_si(signed int i) -> signed int
+
+
+    >>> print (f_l.__doc__)
+    f_l(long int l) -> long int
+
+    >>> print (f_ul.__doc__)
+    f_ul(unsigned long int l) -> unsigned long int
+
+    >>> print (f_sl.__doc__)
+    f_sl(signed long int l) -> signed long int
+
+
+    >>> print (f_L.__doc__)
+    f_L(long long int L) -> long long int
+
+    >>> print (f_uL.__doc__)
+    f_uL(unsigned long long int L) -> unsigned long long int
+
+    >>> print (f_sL.__doc__)
+    f_sL(signed long long int L) -> signed long long int
+
+
+    >>> print (f_f.__doc__)
+    f_f(float f) -> float
+
+    >>> print (f_d.__doc__)
+    f_d(double d) -> double
+
+    >>> print (f_D.__doc__)
+    f_D(long double D) -> long double
+
+"""
+
+cpdef char f_c(char c):
+    return c
+
+cpdef unsigned char f_uc(unsigned char c):
+    return c
+
+cpdef signed char f_sc(signed char c):
+    return c
+
+
+cpdef short f_s(short s):
+    return s
+
+cpdef unsigned short f_us(unsigned short s):
+    return s
+
+cpdef signed short f_ss(signed short s):
+    return s
+
+
+cpdef int f_i(int i):
+    return i
+
+cpdef unsigned int f_ui(unsigned int i):
+    return i
+
+cpdef signed int f_si(signed int i):
+    return i
+
+
+cpdef long f_l(long l):
+    return l
+
+cpdef unsigned long f_ul(unsigned long l):
+    return l
+
+cpdef signed long f_sl(signed long l):
+    return l
+
+
+cpdef long long f_L(long long L):
+    return L
+
+cpdef unsigned long long f_uL(unsigned long long L):
+    return L
+
+cpdef signed long long f_sL(signed long long L):
+    return L
+
+
+cpdef float f_f(float f):
+    return f
+
+cpdef double f_d(double d):
+    return d
+
+cpdef long double f_D(long double D):
+    return D
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to