#8244: Annoying warnings when building the HTML reference manual
-----------------------------+----------------------------------------------
   Reporter:  mpatel         |       Owner:  mvngu     
       Type:  defect         |      Status:  new       
   Priority:  major          |   Milestone:  sage-4.3.3
  Component:  documentation  |    Keywords:            
     Author:                 |    Upstream:  N/A       
   Reviewer:                 |      Merged:            
Work_issues:                 |  
-----------------------------+----------------------------------------------

Comment(by mpatel):

 I'm not very familiar with
 [http://en.wikipedia.org/wiki/Abstract_syntax_tree ASTs] (or
 [http://docs.python.org/library/ast.html ast]), but with
 {{{
 #!python
 import ast
 import inspect
 import sage.misc.sageinspect as sms

 class SageVisitor(ast.NodeVisitor):
     def visit_Name(self, node):
         what = node.id
         if what == 'None':
             return None
         elif what == 'True':
             return True
         elif what == 'False':
             return False
         return node.id

     def visit_Num(self, node):
         return node.n

     def visit_Str(self, node):
         return node.s

     def visit_List(self, node):
         t = []
         for n in node.elts:
             t.append(self.visit(n))
         return t

     def visit_Tuple(self, node):
         t = []
         for n in node.elts:
             t.append(self.visit(n))
         return tuple(t)

     def visit_Dict(self, node):
         d = {}
         for k, v in zip(node.keys, node.values):
             d[self.visit(k)] = self.visit(v)
         return d


 def getargspec_via_ast(source):
     if not isinstance(source, basestring):
         source = sms.sage_getsource(source)

     ast_args = ast.parse(source.lstrip()).body[0].args

     args = []
     defaults = []

     for a in ast_args.args:
         args.append(SageVisitor().visit(a))

     for d in ast_args.defaults:
         defaults.append(SageVisitor().visit(d))

     return inspect.ArgSpec(args, ast_args.vararg, ast_args.kwarg,
                            tuple(defaults) if defaults else None)
 }}}
 I get
 {{{
 #!python
 sage: inspect.getargspec(factor) == getargspec_via_ast(factor)
 True
 sage: getargspec_via_ast(sage.plot.plot3d.base.Graphics3d.export_jmol)
 ArgSpec(args=['self', 'filename', 'force_reload', 'zoom', 'spin',
 'background', 'stereo', 'mesh', 'dots', 'perspective_depth',
 'orientation'], varargs=None, keywords='ignored_kwds',
 defaults=('jmol_shape.jmol', False, 100, False, (1, 1, 1), False, False,
 False, True, (-764, -346, -545, 76.390000000000001)))
 }}}
 Maybe we can use this as a last resort?  I think we'd first need to remove
 Cython-specific constructs.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8244#comment:5>
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].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to