#17814: Make calling a cached method independent of source code inspection
--------------------------------+------------------------
       Reporter:  SimonKing     |        Owner:
           Type:  defect        |       Status:  new
       Priority:  major         |    Milestone:  sage-6.6
      Component:  distribution  |   Resolution:
       Keywords:                |    Merged in:
        Authors:                |    Reviewers:
Report Upstream:  N/A           |  Work issues:
         Branch:                |       Commit:
   Dependencies:                |     Stopgaps:
--------------------------------+------------------------

Comment (by SimonKing):

 Here one can see how introspection enters:
 {{{
 sage: K=GF(5)
 sage: C=type(K)
 sage: C.factored_order
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)
 <ipython-input-4-d955bd892332> in <module>()
 ----> 1 C.factored_order

 /home/king/Sage/git/sage/src/sage/misc/cachefunc.pyx in
 sage.misc.cachefunc.CachedMethod.__get__
 (build/cythonized/sage/misc/cachefunc.c:15452)()
    2673         f = (<CachedFunction>self._cachedfunc).f
    2674         if self.nargs==0:
 -> 2675             args, varargs, keywords, defaults = sage_getargspec(f)
    2676             if varargs is None and keywords is None and
 len(args)<=1:
    2677                 self.nargs = 1

 /home/king/Sage/git/sage/local/lib/python2.7/site-
 packages/sage/misc/sageinspect.pyc in sage_getargspec(obj)
    1394         except TypeError: # arg is not a code object
    1395         # The above "hopefully" was wishful thinking:
 -> 1396             return
 inspect.ArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))
    1397             #return _sage_getargspec_from_ast(sage_getsource(obj))
    1398     try:

 /home/king/Sage/git/sage/local/lib/python2.7/site-
 packages/sage/misc/sageinspect.pyc in _sage_getargspec_cython(source)
    1006
    1007     """
 -> 1008     defpos = source.find('def ')
    1009     assert defpos > -1, "The given source does not contain 'def'"
    1010     s = source[defpos:].strip()

 AttributeError: 'NoneType' object has no attribute 'find'
 }}}
 So: cached_method tries to determine the number of arguments. This is
 because there is a special implementation for functions with no argument
 (except `self`).

 In other words, the wrong behaviour could be fixed by finding a way to get
 the number of arguments (or better the argspec) of a cython function
 without looking at its source code. I'll see if that's possible. So, the
 fix will likely be in `sage.misc.sageinspect`, not in
 `sage.misc.cachefunc`.

--
Ticket URL: <http://trac.sagemath.org/ticket/17814#comment:3>
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to