sagemath / sage

Main repository of SageMath. Now open for Issues and Pull Requests.
https://www.sagemath.org
Other
1.08k stars 394 forks source link

Using run_doctests within Sage breaks REPL #37849

Open cyrilbouvier opened 3 weeks ago

cyrilbouvier commented 3 weeks ago

Steps To Reproduce

  1. Create a empty file empty.sage
  2. Run sage
  3. Inside sage
    sage: 42
    sage: run_doctests('empty.sage')
    sage: 42

Expected Behavior

sage: 42
42
sage: run_doctests('empty.sage')
too few successful tests, not using stored timings
Running doctests with ID 2024-04-22-11-20-21-e842e5ca.
Git branch: develop
Git ref: 10.3-dirty
Running with SAGE_LOCAL='~/src/sage-10.3/local' and SAGE_VENV='~/src/sage-10.3/local/var/lib/sage/venv-python3.11.1'
Using --optional=sage
Features to be detected: 4ti2,benzene,bliss,buckygen,conway_polynomials,csdp,cvxopt,cvxopt,database_cremona_ellcurve,database_cremona_mini_ellcurve,database_cubic_hecke,database_ellcurves,database_graphs,database_jones_numfield,database_knotinfo,dvipng,fpylll,fricas,gap_package_atlasrep,gap_package_design,gap_package_grape,gap_package_guava,gap_package_hap,gap_package_polycyclic,gap_package_qpa,gap_package_quagroup,gfan,graphviz,imagemagick,ipython,jmol,jupymake,kenzo,latte_int,lrcalc_python,lrslib,matroid_database,mcqd,meataxe,mpmath,msolve,nauty,networkx,numpy,palp,pandoc,pdf2svg,pdftocairo,pexpect,phitigra,pillow,plantri,polytopes_db,polytopes_db_4d,pplpy,primecountpy,ptyprocess,pynormaliz,pyparsing,python_igraph,requests,rubiks,sage.combinat,sage.geometry.polyhedron,sage.graphs,sage.groups,sage.libs.braiding,sage.libs.ecl,sage.libs.flint,sage.libs.gap,sage.libs.linbox,sage.libs.m4ri,sage.libs.ntl,sage.libs.pari,sage.libs.singular,sage.misc.cython,sage.modular,sage.modules,sage.numerical.mip,sage.plot,sage.rings.complex_double,sage.rings.finite_rings,sage.rings.function_field,sage.rings.number_field,sage.rings.padics,sage.rings.polynomial.pbori,sage.rings.real_double,sage.rings.real_mpfr,sage.sat,sage.schemes,sage.symbolic,sage_numerical_backends_coin,sagemath_doc_html,scipy,singular,sphinx,symengine_py,sympy,tdlib,threejs
Doctesting 1 file.
sage -t --random-seed=0 ~/current-dir/empty.sage
    [0 tests, 0.00 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 0.0 seconds
    cpu time: 0.0 seconds
    cumulative wall time: 0.0 seconds
Features detected for doctesting: 
sage: 42
42

Actual Behavior

The second sage: 42 fails:

sage: 42
42
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 Integer(42)

File ~/src/sage-10.3/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/IPython/core/displayhook.py:268, in DisplayHook.__call__(self, result)
    266 self.start_displayhook()
    267 self.write_output_prompt()
--> 268 format_dict, md_dict = self.compute_format_data(result)
    269 self.update_user_ns(result)
    270 self.fill_exec_result(result)

File ~/src/sage-10.3/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/IPython/core/displayhook.py:157, in DisplayHook.compute_format_data(self, result)
    127 def compute_format_data(self, result):
    128     """Compute format data of the object to be displayed.
    129 
    130     The format data is a generalization of the :func:`repr` of an object.
   (...)
    155 
    156     """
--> 157     return self.shell.display_formatter.format(result)

File ~/src/sage-10.3/src/sage/repl/display/formatter.py:191, in SageDisplayFormatter.format(self, obj, include, exclude)
    114 def format(self, obj, include=None, exclude=None):
    115     r"""
    116     Use the Sage rich output instead of IPython
    117 
   (...)
    189         I am repper
    190     """
--> 191     sage_format, sage_metadata = self.dm.displayhook(obj)
    192     assert PLAIN_TEXT in sage_format, 'plain text is always present'
    194     # use Sage rich output for any except those native to IPython, but only
    195     # if it is not plain and dull

TypeError: cannot unpack non-iterable NoneType object

Additional Information

I follow the instruction from https://doc.sagemath.org/html/en/developer/doctesting.html#doctesting-from-within-sage, but each time I run run_doctests, I had to quit sage and restart it.

Environment

- **OS**: Debian 11
- **Sage Version**: Sage 9.8, Sage 10.0, Sage 10.3 and 10.4.beta1

Checklist