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

Comment (by SimonKing):

 Replying to [comment:14 jdemeyer]:
 > Building the documentation fails badly:
 > {{{
 >
 
/release/merger/sage-5.7.beta3/devel/sage/doc/en/reference/sage/algebras/letterplace/free_algebra_element_letterplace.rst:11:
 WARNING: error while formatting signature for
 sage.algebras.letterplace.free_algebra_element_letterplace.poly_reduce:
 invalid syntax (<unknown>, line 1)
 > }}}

 OK, let's see what is happening.
 {{{
 sage: from sage.misc.sageinspect import sage_getsource, sage_getargspec
 sage: from sage.algebras.letterplace.free_algebra_element_letterplace
 import poly_reduce
 sage: source = sage_getsource(poly_reduce.__call__)
 sage: print source
     def __call__(self, *args, ring=None, bint interruptible=True,
 attributes=None):
 ...
 }}}

 This actually looks fine, and rather easy to parse.

 But in fact, `_sage_getargspec_from_ast` is to blame, it seems:
 {{{
 sage: from sage.misc.sageinspect import _sage_getargspec_cython,
 _sage_getargspec_from_ast
 sage: _sage_getargspec_from_ast("def __call__(self, *args, ring,
 interruptible, attributes):")
 ------------------------------------------------------------
    File "<unknown>", line 1
      def __call__(self, *args, ring,  interruptible, attributes):
                                   ^
 SyntaxError: invalid syntax
 }}}

 Aha!!! That's very interesting!! Apparently Cython accepts this argument
 definition, but it is indeed a syntax error in Python!
 {{{
 sage: def dummy(self,*args,ring=None,interruptible=True,attributes=None):
 pass
 ------------------------------------------------------------
    File "<ipython console>", line 1
      def dummy(self,*args,ring=None,interruptible=True,attributes=None):
 pass
                              ^
 SyntaxError: invalid syntax
 sage: def dummy(self,ring=None,interruptible=True,attributes=None, *args):
 pass
 ....:
 sage:
 }}}

 So, what can one do? I could try to let `_sage_getargspec_cython`
 determine the varargs and keywords name, and put them to the very end of
 the argument list. The list of arguments/argspec would not change, but it
 would be correct syntax in Python.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14017#comment:15>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to 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