#11298: Extend the capabilities of Sage's introspection
-------------------------+--------------------------------------------------
Reporter: SimonKing | Owner: jason
Type: defect | Status: needs_review
Priority: major | Milestone: sage-4.7.1
Component: misc | Keywords: edit sageinspect
Work_issues: | Upstream: N/A
Reviewer: | Author: Simon King
Merged: | Dependencies: #9976
-------------------------+--------------------------------------------------
Comment(by SimonKing):
Replying to [comment:20 jhpalmieri]:
> What is `type` here? Can you give me an example which will reach this
code?
A concrete example (using the meataxe wrapper from my cohomology spkg):
{{{
sage: from sage.misc.sageinspect import sage_getsourcelines
sage: from pGroupCohomology.mtx import MTX
sage: M = MTX(5,[[1,2],[3,4]])
sage: sage_getsourcelines(M)
---------------------------------------------------------------------------
IOError Traceback (most recent call
last)
/home/king/<ipython console> in <module>()
/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-
packages/sage/misc/sageinspect.pyc in sage_getsourcelines(obj, is_binary)
1407 if pos is None:
1408 try:
-> 1409 return inspect.getsourcelines(obj)
1410 except IOError:
1411 if obj.__class__ != type:
/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python/inspect.pyc in
getsourcelines(object)
676 original source file the first line of code was found. An
IOError is
677 raised if the source code cannot be retrieved."""
--> 678 lines, lnum = findsource(object)
679
680 if ismodule(object): return lines, 0
/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-
packages/IPython/ultraTB.pyc in findsource(object)
175 return lines, candidates[0][1]
176 else:
--> 177 raise IOError('could not find class definition')
178
179 if ismethod(object):
IOError: could not find class definition
}}}
Since `M` can not provide its source lines, the source lines of
`M.__class__` (i.e., of `MTX`) are sought.
Since the source lines of `MTX` can not be found (with the first three
methods), the inspect module raises a `IOError`. It is caught, but
reraised, since `MTX.__class__` is the type `type` and hence an infinite
recursion must be prevented.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11298#comment:23>
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.