ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 11 Mar 2021 04:02:36 +0100The function run_doctests creates a TypeErrorhttps://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/Hello everyone,
I've been writing a sage module in which I've written some documentation examples and tests. I wanted to run a doctest just to verify if everything is correct but function "run_doctests" seems to introduce a non-expected bug in the software. Here's an exampe:
sage: run_doctests("module.sage")
too few successful tests, not using stored timings
Running doctests with ID 2021-03-10-10-13-36-df8ccbc8.
Using --optional=sage
Doctesting 1 file.
sage -t /path-to-module.sage
[40 tests, 0.07 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 0.1 seconds
cpu time: 0.1 seconds
cumulative wall time: 0.1 seconds
sage: M = ModularForms()
sage: M
Modular Forms space of dimension 0 for Modular Group SL(2,Z) of weight 2 over Rational Field
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/all_cmdline.py in <module>
----> 1 M
/usr/lib/python3/dist-packages/IPython/core/displayhook.py in __call__(self, result)
260 self.start_displayhook()
261 self.write_output_prompt()
--> 262 format_dict, md_dict = self.compute_format_data(result)
263 self.update_user_ns(result)
264 self.fill_exec_result(result)
/usr/lib/python3/dist-packages/IPython/core/displayhook.py in compute_format_data(self, result)
149
150 """
--> 151 return self.shell.display_formatter.format(result)
152
153 # This can be set to True by the write_output_prompt method in a subclass
/usr/lib/python3/dist-packages/sage/repl/display/formatter.py in format(self, obj, include, exclude)
198 """
199 # First, use Sage rich output if there is any
--> 200 sage_format, sage_metadata = self.dm.displayhook(obj)
201 assert PLAIN_TEXT in sage_format, 'plain text is always present'
202 if not set(sage_format.keys()).issubset(self.default_mime()):
TypeError: cannot unpack non-iterable NoneType object
Here's more info about the error: it happens whenever I use the run_doctests function. The run_doctests seems to work as it should. However, the problem occurs after I used this function. For example, If I define any object from any class (in my example ModularForms), then when use the special method _repr_ of that object I obtain this error message. I don't think this have anything to do with the ModularForms class.
Do anybody else know what could introduce this error? I was wondering if this error comes from my module or from Sagemath. In my module, I've been following the general conventions of the developper guide.
I've tried both SageMath version 9.0 (from the debian SID package) and SageMath version 9.3.beta8 (compiled from source) and I've got the same error with both versions. If this error comes from the software, I shall open a sage-trac ticket about this issue.
Thank you very much in advance!
edit: I added more information about the issue.Wed, 10 Mar 2021 16:42:35 +0100https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/Answer by Sébastien for <p>Hello everyone,</p>
<p>I've been writing a sage module in which I've written some documentation examples and tests. I wanted to run a doctest just to verify if everything is correct but function "run_doctests" seems to introduce a non-expected bug in the software. Here's an exampe:</p>
<pre><code>sage: run_doctests("module.sage")
too few successful tests, not using stored timings
Running doctests with ID 2021-03-10-10-13-36-df8ccbc8.
Using --optional=sage
Doctesting 1 file.
sage -t /path-to-module.sage
[40 tests, 0.07 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 0.1 seconds
cpu time: 0.1 seconds
cumulative wall time: 0.1 seconds
sage: M = ModularForms()
sage: M
Modular Forms space of dimension 0 for Modular Group SL(2,Z) of weight 2 over Rational Field
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/all_cmdline.py in <module>
----> 1 M
/usr/lib/python3/dist-packages/IPython/core/displayhook.py in __call__(self, result)
260 self.start_displayhook()
261 self.write_output_prompt()
--> 262 format_dict, md_dict = self.compute_format_data(result)
263 self.update_user_ns(result)
264 self.fill_exec_result(result)
/usr/lib/python3/dist-packages/IPython/core/displayhook.py in compute_format_data(self, result)
149
150 """
--> 151 return self.shell.display_formatter.format(result)
152
153 # This can be set to True by the write_output_prompt method in a subclass
/usr/lib/python3/dist-packages/sage/repl/display/formatter.py in format(self, obj, include, exclude)
198 """
199 # First, use Sage rich output if there is any
--> 200 sage_format, sage_metadata = self.dm.displayhook(obj)
201 assert PLAIN_TEXT in sage_format, 'plain text is always present'
202 if not set(sage_format.keys()).issubset(self.default_mime()):
TypeError: cannot unpack non-iterable NoneType object
</code></pre>
<p>Here's more info about the error: it happens whenever I use the run_doctests function. The run_doctests seems to work as it should. However, the problem occurs after I used this function. For example, If I define any object from any class (in my example ModularForms), then when use the special method _repr_ of that object I obtain this error message. I don't think this have anything to do with the ModularForms class.</p>
<p>Do anybody else know what could introduce this error? I was wondering if this error comes from my module or from Sagemath. In my module, I've been following the general conventions of the developper guide. </p>
<p>I've tried both SageMath version 9.0 (from the debian SID package) and SageMath version 9.3.beta8 (compiled from source) and I've got the same error with both versions. If this error comes from the software, I shall open a sage-trac ticket about this issue.</p>
<p>Thank you very much in advance!</p>
<p>edit: I added more information about the issue.</p>
https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?answer=56108#post-id-56108Instead of
sage: run_doctests("module.sage")
in the sage console (which runs the code and may have side effects), I would recommand to run instead:
$ sage -t module.sage
from the command line. You may also want to read the help since it has many options:
$ sage -t -hWed, 10 Mar 2021 21:03:54 +0100https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?answer=56108#post-id-56108Comment by DavidAyotte for <p>Instead of</p>
<pre><code> sage: run_doctests("module.sage")
</code></pre>
<p>in the sage console (which runs the code and may have side effects), I would recommand to run instead:</p>
<pre><code>$ sage -t module.sage
</code></pre>
<p>from the command line. You may also want to read the help since it has many options:</p>
<pre><code>$ sage -t -h
</code></pre>
https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56114#post-id-56114Oh, thanks for pointing this ticket to me. I wasn't aware of it. I guess that I will just do the tests in the console as I am unsure about how to fix that. Thanks!Thu, 11 Mar 2021 04:02:36 +0100https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56114#post-id-56114Comment by John Palmieri for <p>Instead of</p>
<pre><code> sage: run_doctests("module.sage")
</code></pre>
<p>in the sage console (which runs the code and may have side effects), I would recommand to run instead:</p>
<pre><code>$ sage -t module.sage
</code></pre>
<p>from the command line. You may also want to read the help since it has many options:</p>
<pre><code>$ sage -t -h
</code></pre>
https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56113#post-id-56113This has been noticed before, but no solutions yet: https://trac.sagemath.org/ticket/24866Thu, 11 Mar 2021 03:36:53 +0100https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56113#post-id-56113Comment by John Palmieri for <p>Instead of</p>
<pre><code> sage: run_doctests("module.sage")
</code></pre>
<p>in the sage console (which runs the code and may have side effects), I would recommand to run instead:</p>
<pre><code>$ sage -t module.sage
</code></pre>
<p>from the command line. You may also want to read the help since it has many options:</p>
<pre><code>$ sage -t -h
</code></pre>
https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56112#post-id-56112It looks like it's buggy in how it interacts with an interactive Sage. The underlying code of `run_doctests` is the engine that runs all of Sage's doctests, just via `sage -t ...` rather than interactively. The underlying code is very careful about setting the environment so that doctesting is in a sane controlled situation, but maybe it's bad at restoring to the original environment when it's done.Thu, 11 Mar 2021 03:35:18 +0100https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56112#post-id-56112Comment by DavidAyotte for <p>Instead of</p>
<pre><code> sage: run_doctests("module.sage")
</code></pre>
<p>in the sage console (which runs the code and may have side effects), I would recommand to run instead:</p>
<pre><code>$ sage -t module.sage
</code></pre>
<p>from the command line. You may also want to read the help since it has many options:</p>
<pre><code>$ sage -t -h
</code></pre>
https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56109#post-id-56109In other words, run_doctests is buggy and should not be used? Has anyone ever investigated the nature of those bugs?Wed, 10 Mar 2021 21:16:49 +0100https://ask.sagemath.org/question/56105/the-function-run_doctests-creates-a-typeerror/?comment=56109#post-id-56109