#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]:
 > This looks pretty good to me.  I have one question: in
 `sage_getsourcelines`, lines 1408-1411, you have the code
 > ...
 >
 > What is `type` here?  Can you give me an example which will reach this
 code?

 By `type`, I mean the type `type`, such as here:
 {{{
 sage: 1.__class__
 <type 'sage.rings.integer.Integer'>
 sage: 1.__class__.__class__
 <type 'type'>
 }}}

 The idea of the code lines in question is as follows:

 Let `obj` be the object whose source lines we want to determine. It is not
 necessarily true that the correct source lines for `obj` coincide with the
 source lines of its class (notorious counter example: decorated methods).
 Therefore, we need to try harder.

 - First, it is attempted to get the position of the source code from what
 `inspect.getdoc` returns (lines 1400-1401)

 - Second (if "first" fails), the same is attempted with what
 `_sage_getdoc_unformatted` returns (lines 1403-1404). For a reason that I
 don't understand, one can not replace the first step by the second step:
 The comment that I inserted states that a mysterious import error would
 occur at startup.

 - Third (if "second" fails as well), it is tested whether the inspect
 module can provide the source lines of the object `obj` (line 1407).

 - Last resort (if "third" fails), we replace `obj` by `obj.__class__`.
 That is not desired for decorated methods, but these are supposed to
 provide the source lines in a different way, so that one of the first
 three methods should succeed. I think as  a last resort it is ok... (line
 1410).

 There is one obvious problem with the "last resort". If the source lines
 of `obj.__class__` can not be found (e.g., if `obj.__class__` is defined
 in an spkg, not in the Sage library) then as a last resort one would try
 to get  `obj.__class__.__class__`, but that is the type `type` (see
 example above), which is defined in the Python spkg and can thus not be
 found. Infinite recursion.

 In order to avoid the infinite recursion, an error is raised if
 `obj.__class__` is the type `type`, which is, in particular, the case if
 `obj` is not a class instance but a class.

 I hope that answers your question...

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11298#comment:22>
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