#14017: Determine the correct argspec for python functions defined in cython 
files
------------------------------------------------+---------------------------
       Reporter:  SimonKing                     |         Owner:  jason   
           Type:  defect                        |        Status:  new     
       Priority:  major                         |     Milestone:  sage-5.7
      Component:  misc                          |    Resolution:          
       Keywords:  introspection cython argspec  |   Work issues:          
Report Upstream:  N/A                           |     Reviewers:          
        Authors:                                |     Merged in:          
   Dependencies:                                |      Stopgaps:          
------------------------------------------------+---------------------------

Comment (by SimonKing):

 Actually a part of the current doctests expect wrong answers:
 {{{
         sage: from sage.misc.sageinspect import _sage_getargspec_cython as
 sgc

 # That is ok:
         sage: sgc("cpdef double abc(self, x=None, base=0):")
         (['self', 'x', 'base'], None, None, (None, 0))
         sage: sgc("def __init__(self, x=None, unsigned int base=0):")
         (['self', 'x', 'base'], None, None, (None, 0))

 # The following is wrong, and is the main reason why we couldnt' simply
 # put UniqueRepresentation into a Cython file to make it faster:
         sage: sgc('def o(p, *q, r={}, **s) except? -1:')
         (['p', '*q', 'r', '**s'], None, None, ({},))

 # That is ok:
         sage: sgc('cpdef how(r=(None, "u:doing?")):')
         (['r'], None, None, ((None, 'u:doing?'),))
         sage: sgc('def _(x="):"):')
         (['x'], None, None, ('):',))
         sage: sgc('def f(z = {(1,2,3): True}):\n    return z')
         (['z'], None, None, ({(1, 2, 3): True},))

 # The following gives a valid function definition in a cython file,
 # hence, there must be no error when determining the argspec
         sage: sgc('def f(double x, z = {(1,2,3): True}):\n    return z')
         Traceback (most recent call last):
         ...
         ValueError: Could not parse cython argspec
 }}}

 Last night I have coded something which I think is a finite state
 automaton that correctly parses any argspec, provided that the given input
 is valid in Cython. Hence, I do not claim that my code would detect all
 possible syntax errors; but if there is no syntax error, then the output
 should be the correct argspec.

 In the above doctests, my code would give the correct results. But I need
 some more tests at this point, and also I am not sure whether I should try
 to detect some more syntactical problems.

 For example, I currently have the reasonable answer
 {{{
 sage: sgc('def o(int * bla p, *q, r={}, **s) except? -1:')
 (['p', 'r'], 'q', 's', ['{}'])
 }}}
 (here, `int * bla` is thought of as a type definition in Cython, which is
 of course wrong but doesn't matter), but I also get something that could
 easily be avoided:
 {{{
 sage: sgc('def o(int * bla p, *q, r={}, , **s) except? -1:')
 (['p', 'r', 's'], 'q', None, ['{}'])
 }}}
 (here, `, **` is thought of as a type definition in Cython, but of course
 it would be straight forward to recognise that there is one illegal comma
 inserted).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14017#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to