Sage: Ticket #11298: Extend the capabilities of Sage's introspection
https://trac.sagemath.org/ticket/11298
<p>
The following used to fail:
</p>
<pre class="wiki">sage: x??
Error getting source: could not find class definition
sage: P.<x,y> = QQ[]
sage: P??
Error getting source: could not find class definition
sage: I??
Error getting source: could not find class definition
</pre><p>
Similarly, the edit command did not work in these case.
</p>
<p>
With my patch, all that works. Moreover, both sage.misc.edit_module and sage.misc.sageinspect are put into the reference manual.
</p>
<p>
Note that this may be related with <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a>: <code>sage.misc.sage_getfile</code> and <code>sage_getsourcelines</code> could be a reliable tool to get information on how and from where to import a given object. Therefore Cc to the participants of that ticket.
</p>
<p>
Moreover, Cc to <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>. Reason:
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
<p>
Apply
</p>
<ul><li><a class="attachment" href="https://trac.sagemath.org/attachment/ticket/11298/trac11298_introspection_and_edit.patch" title="Attachment 'trac11298_introspection_and_edit.patch' in Ticket #11298">trac11298_introspection_and_edit.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/11298/trac11298_introspection_and_edit.patch" title="Download"></a>
</li><li><a class="attachment" href="https://trac.sagemath.org/attachment/ticket/11298/trac11298_singular_standard_options.rebase4.7.1.a1.patch" title="Attachment 'trac11298_singular_standard_options.rebase4.7.1.a1.patch' in Ticket #11298">trac11298_singular_standard_options.rebase4.7.1.a1.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/11298/trac11298_singular_standard_options.rebase4.7.1.a1.patch" title="Download"></a>
</li><li><a class="attachment" href="https://trac.sagemath.org/attachment/ticket/11298/trac_11298-ref.patch" title="Attachment 'trac_11298-ref.patch' in Ticket #11298">trac_11298-ref.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/11298/trac_11298-ref.patch" title="Download"></a>
</li></ul>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/11298
Trac 1.1.6SimonKingThu, 05 May 2011 09:32:02 GMTstatus changed
https://trac.sagemath.org/ticket/11298#comment:1
https://trac.sagemath.org/ticket/11298#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
<p>
For the patchbot:
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
TicketSimonKingThu, 05 May 2011 10:10:44 GMT
https://trac.sagemath.org/ticket/11298#comment:2
https://trac.sagemath.org/ticket/11298#comment:2
<p>
Correcting a misspelling.
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
TicketSimonKingThu, 05 May 2011 12:16:30 GMT
https://trac.sagemath.org/ticket/11298#comment:3
https://trac.sagemath.org/ticket/11298#comment:3
<p>
Note that, with the patch, <code>functools.partial</code> objects can be reasonably edited as well:
</p>
<pre class="wiki">edit(sage.combinat.partition_algebra.SetPartitionsAk,'vim')
</pre><p>
opens vim at line 31 of sage/combinat/partition_algebra.py:
</p>
<pre class="wiki">def create_set_partition_function(letter, k):
"""
EXAMPLES::
sage: from sage.combinat.partition_algebra import create_set_partition_function
sage: create_set_partition_function('A', 3)
Set partitions of {1, ..., 3, -1, ..., -3}
"""
from sage.functions.all import floor
if isinstance(k, (int, Integer)):
if k > 0:
return globals()['SetPartitions' + letter + 'k_k'](k)
elif is_RealNumber(k):
if k - math.floor(k) == 0.5:
return globals()['SetPartitions' + letter + 'khalf_k'](floor(k))
raise ValueError, "k must be an integer or an integer + 1/2"
</pre><p>
and indeed that is the underlying definition of <code>SetPartitionsAk</code>; see line 53, which is
</p>
<pre class="wiki">SetPartitionsAk = functools.partial(create_set_partition_function,"A")
</pre>
TicketSimonKingThu, 05 May 2011 13:23:32 GMT
https://trac.sagemath.org/ticket/11298#comment:4
https://trac.sagemath.org/ticket/11298#comment:4
<p>
I found one more case where source code inspection failed: the (lib)singular_standard_options wrapper.
</p>
<p>
With the new patch, we have
</p>
<pre class="wiki">sage: P.<x,y> = QQ[]
sage: I = P*[x,y]
sage: edit(I.interreduced_basis,'vim')
...
@singular_standard_options
@libsingular_standard_options
def interreduced_basis(self):
r"""
If this ideal is spanned by `(f_1, ..., f_n)` this method
returns `(g_1, ..., g_s)` such that:
- `(f_1,...,f_n) = (g_1,...,g_s)`
- `LT(g_i) != LT(g_j)` for all `i != j`
...
</pre><p>
which would previously just show the code of the wrapper, not of the wrapped method.
</p>
<p>
I wonder why the patchbot complains. In particular, why does the patchbot mention my patch from trac ticket <a class="closed ticket" href="https://trac.sagemath.org/ticket/11115" title="enhancement: Rewrite cached_method in Cython (closed: fixed)">#11115</a> - it shouldn't be a dependency, or should it? Let's see.
</p>
<p>
For now:
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
TicketSimonKingThu, 05 May 2011 13:28:06 GMT
https://trac.sagemath.org/ticket/11298#comment:5
https://trac.sagemath.org/ticket/11298#comment:5
<p>
I just verified: In my patch queue, the patches from <a class="closed ticket" href="https://trac.sagemath.org/ticket/11115" title="enhancement: Rewrite cached_method in Cython (closed: fixed)">#11115</a> come <em>after</em> <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/11298/trac11298_introspection_and_edit.patch" title="Attachment 'trac11298_introspection_and_edit.patch' in Ticket #11298">trac11298_introspection_and_edit.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/11298/trac11298_introspection_and_edit.patch" title="Download"></a>
</p>
<p>
In other words, the behaviour of the patchbot seems very strange to me.
</p>
TicketSimonKingThu, 05 May 2011 13:40:09 GMT
https://trac.sagemath.org/ticket/11298#comment:6
https://trac.sagemath.org/ticket/11298#comment:6
<p>
I still think that the patchbot goofed it, but I did as well: The old version of the second patch would really be on top of <a class="closed ticket" href="https://trac.sagemath.org/ticket/11115" title="enhancement: Rewrite cached_method in Cython (closed: fixed)">#11115</a> (but not the first). I was just updating it, so that we have:
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
<p>
and nothing else. Could be that I need to fix some tests, though...
</p>
TicketSimonKingThu, 05 May 2011 13:54:00 GMT
https://trac.sagemath.org/ticket/11298#comment:7
https://trac.sagemath.org/ticket/11298#comment:7
<p>
Adding "r" to one doc string (for making the documentation nicely formatted) and correcting one doc test.
</p>
<p>
The tests in sage.misc and in sage.rings.polynomial all pass. Next, I'll run long tests.
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
TicketSimonKingThu, 05 May 2011 14:22:42 GMTstatus changed
https://trac.sagemath.org/ticket/11298#comment:8
https://trac.sagemath.org/ticket/11298#comment:8
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
</ul>
<p>
I'll try to trigger the patchbot by changing to "needs work"...
</p>
TicketSimonKingThu, 05 May 2011 14:23:04 GMT
https://trac.sagemath.org/ticket/11298#comment:9
https://trac.sagemath.org/ticket/11298#comment:9
<p>
... and returning to needs review...
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
TicketSimonKingThu, 05 May 2011 14:23:12 GMTstatus changed
https://trac.sagemath.org/ticket/11298#comment:10
https://trac.sagemath.org/ticket/11298#comment:10
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
</ul>
TicketSimonKingThu, 05 May 2011 14:24:35 GMTattachment set
https://trac.sagemath.org/ticket/11298
https://trac.sagemath.org/ticket/11298
<ul>
<li><strong>attachment</strong>
set to <em>trac11298_introspection_and_edit.patch</em>
</li>
</ul>
<p>
Extend the capabilities of introspection and interactive source code edition
</p>
TicketSimonKingThu, 05 May 2011 14:25:51 GMT
https://trac.sagemath.org/ticket/11298#comment:11
https://trac.sagemath.org/ticket/11298#comment:11
<p>
OK, that did not help. Hence, I submitted the patches again. I wish the red blob would finally vanish!
</p>
<p>
Depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>
</p>
TicketSimonKingThu, 05 May 2011 14:28:41 GMTdependencies set
https://trac.sagemath.org/ticket/11298#comment:12
https://trac.sagemath.org/ticket/11298#comment:12
<ul>
<li><strong>dependencies</strong>
set to <em>#9976</em>
</li>
</ul>
<p>
Ooops, I forgot that since recently there is a form field in which to state dependencies. Let's try it!
</p>
TicketSimonKingThu, 05 May 2011 18:08:09 GMT
https://trac.sagemath.org/ticket/11298#comment:13
https://trac.sagemath.org/ticket/11298#comment:13
<p>
FWIW, long tests pass for me, and I believe that the patchbot has a serious flaw if it can not even deal with a single dependency.
</p>
TicketSimonKingSat, 07 May 2011 19:59:27 GMT
https://trac.sagemath.org/ticket/11298#comment:14
https://trac.sagemath.org/ticket/11298#comment:14
<p>
Now I understand what the patchbot is doing (resp. not doing): It believes that <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a> does not need to be applied, since it is merged. But it does not understand that <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a> is merged in 4.7.1.alpha0, not in 4.7.rc1 (which is what it is starting with).
</p>
TicketSimonKingWed, 25 May 2011 14:00:17 GMTstatus changed; work_issues set
https://trac.sagemath.org/ticket/11298#comment:15
https://trac.sagemath.org/ticket/11298#comment:15
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>work_issues</strong>
set to <em>Fix crash at docbuild</em>
</li>
</ul>
<p>
I noticed that building the documentation crashes when the second patch is applied. It is as follows:
</p>
<pre class="wiki">Running Sphinx v1.0.4
loading pickled environment... done
building [html]: targets for 39 source files that are out of date
updating environment: 0 added, 39 changed, 0 removed
reading sources... [ 33%] sage/rings/polynomial/multi_polynomial_ideal_libsingular
Exception occurred:
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/config.py", line 207, in __getattr__
raise AttributeError('No such config value: %s' % name)
AttributeError: No such config value: autodoc_default_flags
The full traceback has been saved in /tmp/sphinx-err-1tNBmd.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
Build finished. The built documents can be found in /mnt/local/king/SAGE/sage-4.7.rc2/devel/sage/doc/output/html/en/reference
</pre><p>
and the traceback is
</p>
<pre class="wiki"># Sphinx version: 1.0.4
# Docutils version: 0.5 release
# Jinja2 version: 2.5.5
Traceback (most recent call last):
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/cmdline.py", line 173, in main
app.build(force_all, filenames)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/application.py", line 207, in build
self.builder.build_update()
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/builders/__init__.py", line 198, in build_update
'out of date' % len(to_build))
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/builders/__init__.py", line 218, in build
purple, length):
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/builders/__init__.py", line 120, in status_iterator
for item in iterable:
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/environment.py", line 518, in update_generator
self.read_doc(docname, app=app)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/environment.py", line 658, in read_doc
pub.publish()
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/core.py", line 204, in publish
self.settings)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/readers/__init__.py", line 69, in read
self.parse()
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/readers/__init__.py", line 75, in parse
self.parser.parse(self.input, document)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/__init__.py", line 157, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 170, in run
input_source=document['source'])
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/statemachine.py", line 232, in run
context, state, transitions)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/statemachine.py", line 420, in check_line
return method(match, context, next_state)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 2658, in underline
self.section(title, source, style, lineno - 1, messages)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 308, in section
self.new_subsection(title, lineno, messages)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 376, in new_subsection
node=section_node, match_titles=1)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 266, in nested_parse
node=node, match_titles=match_titles)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/statemachine.py", line 232, in run
context, state, transitions)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/statemachine.py", line 420, in check_line
return method(match, context, next_state)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 2241, in explicit_markup
self.explicit_list(blank_finish)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 2269, in explicit_list
match_titles=self.state_machine.match_titles)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 300, in nested_list_parse
node=node, match_titles=match_titles)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/statemachine.py", line 232, in run
context, state, transitions)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/statemachine.py", line 420, in check_line
return method(match, context, next_state)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 2542, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 2251, in explicit_construct
return method(self, expmatch)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 1994, in directive
directive_class, match, type_name, option_presets)
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/docutils/parsers/rst/states.py", line 2043, in run_directive
result = directive_instance.run()
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/ext/autodoc.py", line 1154, in run
if flag in self.env.config.autodoc_default_flags and \
File "/mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/Sphinx-1.0.4-py2.6.egg/sphinx/config.py", line 207, in __getattr__
raise AttributeError('No such config value: %s' % name)
AttributeError: No such config value: autodoc_default_flags
</pre><p>
I have no idea how this can be debugged.
</p>
TicketSimonKingThu, 26 May 2011 06:03:05 GMT
https://trac.sagemath.org/ticket/11298#comment:16
https://trac.sagemath.org/ticket/11298#comment:16
<p>
Perhaps it would be worth while to follow a more conceptual approach.
</p>
<p>
Currently, <code>singular_standard_options</code> and <code>magma_standard_options</code> applied to a method <code>func</code> simply return a function <code>wrapper</code>, that does not know about <code>func</code> (except its doc string, but I think that's a bad idea as well since copying that string costs time). So, introspection does not work. I tried to provide <code>wrapper</code> with the tools needed to make it work, but apparently it was not so easy.
</p>
<p>
But there is the <code>sage_wraps</code> factory, and I think I should try to use it!
</p>
TicketSimonKingThu, 26 May 2011 07:08:45 GMTattachment set
https://trac.sagemath.org/ticket/11298
https://trac.sagemath.org/ticket/11298
<ul>
<li><strong>attachment</strong>
set to <em>trac11298_singular_standard_options.patch</em>
</li>
</ul>
<p>
Introspection for sage.misc.decorators.sage_wraps, applied for singular_standard_options. Put decorators into references.
</p>
TicketSimonKingThu, 26 May 2011 07:11:56 GMTstatus changed; work_issues deleted
https://trac.sagemath.org/ticket/11298#comment:17
https://trac.sagemath.org/ticket/11298#comment:17
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
<li><strong>work_issues</strong>
<em>Fix crash at docbuild</em> deleted
</li>
</ul>
<p>
The second patch has now been updated.
</p>
<p>
The problem seems solved: I touched all files in sage/rings/polynomial, did <code>sage -b</code> and then built the documentation without problem.
</p>
<p>
Moreover, I fixed some syntax error in the documentation, and I've put sage.misc.decorators into the reference manual.
</p>
<p>
So, it is needing review again!
</p>
TicketburcinTue, 07 Jun 2011 21:10:30 GMTattachment set
https://trac.sagemath.org/ticket/11298
https://trac.sagemath.org/ticket/11298
<ul>
<li><strong>attachment</strong>
set to <em>trac11298_singular_standard_options.rebase4.7.1.a1.patch</em>
</li>
</ul>
<p>
rebased Simon's patch to 4.7.1.alpha1
</p>
TicketburcinTue, 07 Jun 2011 21:11:53 GMTdescription changed
https://trac.sagemath.org/ticket/11298#comment:18
https://trac.sagemath.org/ticket/11298#comment:18
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/11298?action=diff&version=18">diff</a>)
</li>
</ul>
TicketSimonKingWed, 08 Jun 2011 06:24:08 GMT
https://trac.sagemath.org/ticket/11298#comment:19
https://trac.sagemath.org/ticket/11298#comment:19
<p>
Thank you, Burcin!
</p>
<p>
For the patchbot, that seems to ignore the ticket description:
</p>
<p>
Apply trac11298_introspection_and_edit.patch, trac11298_singular_standard_options.rebase4.7.1.a1.patch
</p>
TicketjhpalmieriWed, 20 Jul 2011 19:50:52 GMT
https://trac.sagemath.org/ticket/11298#comment:20
https://trac.sagemath.org/ticket/11298#comment:20
<p>
This looks pretty good to me. I have one question: in <code>sage_getsourcelines</code>, lines 1408-1411, you have the code
</p>
<div class="wiki-code"><div class="code"><pre> <span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
<span class="k">if</span> obj<span class="o">.</span>__class__ <span class="o">!=</span> <span class="nb">type</span><span class="p">:</span>
<span class="k">return</span> sage_getsourcelines<span class="p">(</span>obj<span class="o">.</span>__class__<span class="p">)</span>
<span class="k">raise</span>
</pre></div></div><p>
What is <code>type</code> here? Can you give me an example which will reach this code?
</p>
TicketjhpalmieriWed, 20 Jul 2011 19:52:47 GMT
https://trac.sagemath.org/ticket/11298#comment:21
https://trac.sagemath.org/ticket/11298#comment:21
<p>
(Is it just the built-in Python <code>type</code> function?)
</p>
TicketSimonKingWed, 20 Jul 2011 20:51:49 GMT
https://trac.sagemath.org/ticket/11298#comment:22
https://trac.sagemath.org/ticket/11298#comment:22
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11298#comment:20" title="Comment 20">jhpalmieri</a>:
</p>
<blockquote class="citation">
<p>
This looks pretty good to me. I have one question: in <code>sage_getsourcelines</code>, lines 1408-1411, you have the code
...
</p>
<p>
What is <code>type</code> here? Can you give me an example which will reach this code?
</p>
</blockquote>
<p>
By <code>type</code>, I mean the type <code>type</code>, such as here:
</p>
<pre class="wiki">sage: 1.__class__
<type 'sage.rings.integer.Integer'>
sage: 1.__class__.__class__
<type 'type'>
</pre><p>
The idea of the code lines in question is as follows:
</p>
<p>
Let <code>obj</code> be the object whose source lines we want to determine. It is not necessarily true that the correct source lines for <code>obj</code> coincide with the source lines of its class (notorious counter example: decorated methods). Therefore, we need to try harder.
</p>
<ul><li>First, it is attempted to get the position of the source code from what <code>inspect.getdoc</code> returns (lines 1400-1401)
</li></ul><ul><li>Second (if "first" fails), the same is attempted with what <code>_sage_getdoc_unformatted</code> 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.
</li></ul><ul><li>Third (if "second" fails as well), it is tested whether the inspect module can provide the source lines of the object <code>obj</code> (line 1407).
</li></ul><ul><li>Last resort (if "third" fails), we replace <code>obj</code> by <code>obj.__class__</code>. 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).
</li></ul><p>
There is one obvious problem with the "last resort". If the source lines of <code>obj.__class__</code> can not be found (e.g., if <code>obj.__class__</code> is defined in an spkg, not in the Sage library) then as a last resort one would try to get <code>obj.__class__.__class__</code>, but that is the type <code>type</code> (see example above), which is defined in the Python spkg and can thus not be found. Infinite recursion.
</p>
<p>
In order to avoid the infinite recursion, an error is raised if <code>obj.__class__</code> is the type <code>type</code>, which is, in particular, the case if <code>obj</code> is not a class instance but a class.
</p>
<p>
I hope that answers your question...
</p>
TicketSimonKingWed, 20 Jul 2011 21:06:41 GMT
https://trac.sagemath.org/ticket/11298#comment:23
https://trac.sagemath.org/ticket/11298#comment:23
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11298#comment:20" title="Comment 20">jhpalmieri</a>:
</p>
<blockquote class="citation">
<p>
What is <code>type</code> here? Can you give me an example which will reach this code?
</p>
</blockquote>
<p>
A concrete example (using the meataxe wrapper from my cohomology spkg):
</p>
<pre class="wiki">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
</pre><p>
Since <code>M</code> can not provide its source lines, the source lines of <code>M.__class__</code> (i.e., of <code>MTX</code>) are sought.
</p>
<p>
Since the source lines of <code>MTX</code> can not be found (with the first three methods), the inspect module raises a <code>IOError</code>. It is caught, but reraised, since <code>MTX.__class__</code> is the type <code>type</code> and hence an infinite recursion must be prevented.
</p>
TicketjhpalmieriWed, 20 Jul 2011 21:33:10 GMTreviewer set
https://trac.sagemath.org/ticket/11298#comment:24
https://trac.sagemath.org/ticket/11298#comment:24
<ul>
<li><strong>reviewer</strong>
set to <em>John Palmieri</em>
</li>
</ul>
<p>
Okay, I'm happy with this. I'm attaching a referee's patch with a few small changes. If you're happy with my changes, please switch the ticket to "positive review".
</p>
<p>
This makes a very nice companion to <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a>.
</p>
TicketjhpalmieriWed, 20 Jul 2011 21:33:30 GMTattachment set
https://trac.sagemath.org/ticket/11298
https://trac.sagemath.org/ticket/11298
<ul>
<li><strong>attachment</strong>
set to <em>trac_11298-ref.patch</em>
</li>
</ul>
<p>
referee patch; apply on top of others
</p>
TicketjhpalmieriWed, 20 Jul 2011 21:35:47 GMTdescription changed
https://trac.sagemath.org/ticket/11298#comment:25
https://trac.sagemath.org/ticket/11298#comment:25
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/11298?action=diff&version=25">diff</a>)
</li>
</ul>
<p>
(The only aspect of the referee's patch worth mentioning is the removal of the import of <code>sage_getsource</code>. This is already done at the top-level of that file, so it doesn't need to be done again.)
</p>
TicketSimonKingWed, 20 Jul 2011 22:44:35 GMTstatus changed
https://trac.sagemath.org/ticket/11298#comment:26
https://trac.sagemath.org/ticket/11298#comment:26
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11298#comment:24" title="Comment 24">jhpalmieri</a>:
</p>
<blockquote class="citation">
<p>
Okay, I'm happy with this. I'm attaching a referee's patch with a few small changes. If you're happy with my changes, please switch the ticket to "positive review".
</p>
</blockquote>
<p>
I am happy with the changes. Thus I change it into a positive review. Thank you very much!
</p>
TicketjdemeyerThu, 21 Jul 2011 12:38:02 GMTmilestone changed
https://trac.sagemath.org/ticket/11298#comment:27
https://trac.sagemath.org/ticket/11298#comment:27
<ul>
<li><strong>milestone</strong>
changed from <em>sage-4.7.1</em> to <em>sage-4.7.2</em>
</li>
</ul>
TicketjdemeyerThu, 28 Jul 2011 20:20:55 GMTstatus changed; work_issues set
https://trac.sagemath.org/ticket/11298#comment:28
https://trac.sagemath.org/ticket/11298#comment:28
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>needs_work</em>
</li>
<li><strong>work_issues</strong>
set to <em>rebase to #11287</em>
</li>
</ul>
<p>
This needs to be rebased to <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a>.
</p>
TicketjhpalmieriThu, 28 Jul 2011 21:26:30 GMT
https://trac.sagemath.org/ticket/11298#comment:29
https://trac.sagemath.org/ticket/11298#comment:29
<p>
After applying the patch at <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a>, these still apply for me, although one does have fuzz. Is the fuzz an issue or are patches actually being rejected?
</p>
TicketSimonKingSun, 31 Jul 2011 07:06:17 GMTstatus changed
https://trac.sagemath.org/ticket/11298#comment:30
https://trac.sagemath.org/ticket/11298#comment:30
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_info</em>
</li>
</ul>
<p>
<Bump>
</p>
<p>
Jeroen, could you please elaborate why you think that it should be rebased?
</p>
TicketjhpalmieriMon, 01 Aug 2011 01:24:09 GMT
https://trac.sagemath.org/ticket/11298#comment:31
https://trac.sagemath.org/ticket/11298#comment:31
<p>
(If all else fails, we can wait until 4.7.2.alpha0 and rebase it with respect to that.)
</p>
TicketjdemeyerMon, 01 Aug 2011 10:08:32 GMT
https://trac.sagemath.org/ticket/11298#comment:32
https://trac.sagemath.org/ticket/11298#comment:32
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11298#comment:29" title="Comment 29">jhpalmieri</a>:
</p>
<blockquote class="citation">
<p>
After applying the patch at <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a>, these still apply for me, although one does have fuzz. Is the fuzz an issue or are patches actually being rejected?
</p>
</blockquote>
<p>
My personal opinion on applying patches with fuzz is that I allow patches with fuzz 1 but not with fuzz 2. I have seen at least two cases where a "fuzz 2" patch was actually wrongly merged (I don't remember which tickets).
</p>
TicketSimonKingMon, 01 Aug 2011 10:30:29 GMT
https://trac.sagemath.org/ticket/11298#comment:33
https://trac.sagemath.org/ticket/11298#comment:33
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11298#comment:32" title="Comment 32">jdemeyer</a>:
</p>
<blockquote class="citation">
<p>
My personal opinion on applying patches with fuzz is that I allow patches with fuzz 1 but not with fuzz 2. I have seen at least two cases where a "fuzz 2" patch was actually wrongly merged (I don't remember which tickets).
</p>
</blockquote>
<p>
OK. Then I'll take care of it.
</p>
TicketSimonKingMon, 01 Aug 2011 11:08:48 GMT
https://trac.sagemath.org/ticket/11298#comment:34
https://trac.sagemath.org/ticket/11298#comment:34
<p>
By the way: When I tried to import the patch from <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a> on top of sage-4.7.rc2, application to doc/en/reference/mist.rst failed. But if I understood correctly, the problem with the patch here is somewhere else, right? And moreover, I should probably get a more recent Sage version...
</p>
TicketSimonKingMon, 01 Aug 2011 11:12:39 GMT
https://trac.sagemath.org/ticket/11298#comment:35
https://trac.sagemath.org/ticket/11298#comment:35
<p>
That's odd!
</p>
<p>
I applied the patches from <a class="closed ticket" href="https://trac.sagemath.org/ticket/11251" title="enhancement: Add todo extension to Sphinx (closed: fixed)">#11251</a>, then <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a>. Then I had fuzz 2 for one of the patches from <a class="closed ticket" href="https://trac.sagemath.org/ticket/9976" title="enhancement: Decorated functions/methods have generic signature in documentation (closed: fixed)">#9976</a> (but they are already merged in 4.7.1.alpha0), and then the patches from here applied <em>cleanly</em> and <em>without fuzz</em>.
</p>
<p>
So, it seems that I should get the latest rc or alpha version of sage, and try again.
</p>
TicketjdemeyerMon, 01 Aug 2011 11:31:15 GMT
https://trac.sagemath.org/ticket/11298#comment:36
https://trac.sagemath.org/ticket/11298#comment:36
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11298#comment:35" title="Comment 35">SimonKing</a>:
Yes, sage-4.7.rc2 is in fact quite old, so please try <a class="ext-link" href="http://boxen.math.washington.edu/home/release/sage-4.7.1.rc1/"><span class="icon"></span>sage-4.7.1.rc1</a> + <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a> (or wait until sage-4.7.2.alpha0 is released and rebase to that).
</p>
TicketSimonKingMon, 01 Aug 2011 15:46:35 GMTattachment set
https://trac.sagemath.org/ticket/11298
https://trac.sagemath.org/ticket/11298
<ul>
<li><strong>attachment</strong>
set to <em>trac11298_singular_standard_options.rebased.patch</em>
</li>
</ul>
<p>
Introspection for sage.misc.decorators.sage_wraps, applied for singular_standard_options. Put decorators into references. Rebased against <a class="closed ticket" href="https://trac.sagemath.org/ticket/11287" title="enhancement: Interface to runsnake and import_statements (closed: fixed)">#11287</a>
</p>
TicketSimonKingMon, 01 Aug 2011 15:48:36 GMTstatus, dependencies, description changed
https://trac.sagemath.org/ticket/11298#comment:37
https://trac.sagemath.org/ticket/11298#comment:37
<ul>
<li><strong>status</strong>
changed from <em>needs_info</em> to <em>needs_review</em>
</li>
<li><strong>dependencies</strong>
changed from <em>#9976</em> to <em>#9976, #11287</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/11298?action=diff&version=37">diff</a>)
</li>
</ul>
<p>
I've built sage-4.7.1.rc1 and rebased the patch.
</p>
<p>
Apply trac11298_introspection_and_edit.patch <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/11298/trac11298_singular_standard_options.rebased.patch" title="Attachment 'trac11298_singular_standard_options.rebased.patch' in Ticket #11298">attachment:trac11298_singular_standard_options.rebased.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/11298/trac11298_singular_standard_options.rebased.patch" title="Download"></a> <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/11298/trac_11298-ref.patch" title="Attachment 'trac_11298-ref.patch' in Ticket #11298">attachment:trac_11298-ref.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/11298/trac_11298-ref.patch" title="Download"></a>
</p>
TicketSimonKingMon, 01 Aug 2011 15:52:10 GMTstatus changed
https://trac.sagemath.org/ticket/11298#comment:38
https://trac.sagemath.org/ticket/11298#comment:38
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
The change of the patch concerns doc/en/misc.rst, and the reason for the change was the fact that the context of the inserted line has changed. In particular, the change in the patch has not changed code or doctests. Therefore I believe that it should be reverted to a positive review.
</p>
<p>
Apply trac11298_introspection_and_edit.patch trac11298_singular_standard_options.rebased.patch trac_11298-ref.patch
</p>
TicketjhpalmieriMon, 01 Aug 2011 21:12:05 GMT
https://trac.sagemath.org/ticket/11298#comment:39
https://trac.sagemath.org/ticket/11298#comment:39
<blockquote class="citation">
<p>
I believe that it should be reverted to a positive review.
</p>
</blockquote>
<p>
I agree. If it's a simple rebase, no new review should be needed. Thanks for taking care of this.
</p>
TicketjdemeyerTue, 02 Aug 2011 19:44:45 GMTstatus changed; resolution, merged set; work_issues deleted
https://trac.sagemath.org/ticket/11298#comment:40
https://trac.sagemath.org/ticket/11298#comment:40
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>work_issues</strong>
<em>rebase to #11287</em> deleted
</li>
<li><strong>merged</strong>
set to <em>sage-4.7.2.alpha1</em>
</li>
</ul>
Ticket