#11817: Use sage_getdoc in sage interpreter when doing "?"
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  jason                       
       Type:  enhancement  |         Status:  needs_review                
   Priority:  major        |      Milestone:  sage-4.7.2                  
  Component:  misc         |       Keywords:  sage_getdoc format embedding
Work_issues:               |       Upstream:  N/A                         
   Reviewer:               |         Author:  Simon King                  
     Merged:               |   Dependencies:  #11815                      
---------------------------+------------------------------------------------
Changes (by newvalueoldvalue):

  * status:  new => needs_review
  * author:  => Simon King


Comment:

 With the attached patch, one can do:
 {{{
 sage: from sage.misc.sagedoc import format
 sage: format?
 Type:           function
 Base Class:     <type 'function'>
 String Form:    <function format at 0xc290c8>
 Namespace:      Interactive
 File:
 /mnt/local/king/SAGE/debug/sage-4.7.2.alpha3-prerelease/local/lib/python2.6
 /site-packages/sage/misc/sagedoc.py
 Definition:     format(s, embedded=False)
 Docstring:
        Format Sage documentation ``s`` for viewing with IPython.

        This calls ``detex`` on ``s`` to convert LaTeX commands to plain
        text, unless the directive ``nodetex`` is given in the first line
        of the string.
 ...
 }}}

 Note that I introduced a `noreplace` directive, and used it on `format`'s
 docstring.

 Also, interactive doc read does not blindly use a custom `_sage_doc_`: It
 will always use `sage_getdoc`, which does preprocessing:
 {{{
 sage: r = 'some doc for a cython method\n`x \\geq y`'
 sage: class Foo:
 ....:     def _sage_doc_(self):
 ....:         return r
 ....:
 sage: f = Foo()
 sage: f?
 Type:           instance
 Base Class:     __main__.Foo
 String Form:    <__main__.Foo instance at 0xb0ce18>
 Namespace:      Interactive
 File:
 /mnt/local/king/SAGE/debug/sage-4.7.2.alpha3-prerelease/local/lib/python2.6
 /site-packages/IPython/FakeModule
 .py
 Docstring:
     some doc for a cython method x >= y

 }}}
 Without the patch, the latex code would be shown.

 If the `noreplace` directive is not used, but the to-be-replaced-with
 object can not be found, the replacement is simply skipped. Some new
 doctest related with directives and replacement:
 {{{
 sage: print format('File: bla.py (starting at line 1)\nnodetex,
 noreplace\n<<<identity_matrix>>>`\\not= 0`')
 File: bla.py (starting at line 1)
 <<<identity_matrix>>>`\not= 0`
 }}}
 {{{
 sage: print format('<<<bla\n<<<bla>>>\n<<<identity_matrix>>>')
 <<<bla <<<bla>>>
 <BLANKLINE>
 Definition: identity_matrix(ring, n=0, sparse=False)
 <BLANKLINE>
    Return the n x n identity matrix over the given ring.
 ...
 }}}

 I didn't run all tests (only those of sage.misc.sagedoc)

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