diff --git a/src/sage/repl/attach.py b/src/sage/repl/attach.py index 11967fbf96..ccb9c4e0c0 100644 --- a/src/sage/repl/attach.py +++ b/src/sage/repl/attach.py @@ -597,12 +597,7 @@ def reload_attached_files_if_modified(): basename = os.path.basename(filename) timestr = time.strftime('%T', mtime) notice = '### reloading attached file {0} modified at {1} ###'.format(basename, timestr) - if ip and ip.pt_cli: - with ip.pt_cli.patch_stdout_context(raw=True): - print(notice) - code = load_wrap(filename, attach=True) - ip.run_cell(code) - elif ip: + if ip: print(notice) code = load_wrap(filename, attach=True) ip.run_cell(code) diff --git a/src/sage/repl/display/fancy_repr.py b/src/sage/repl/display/fancy_repr.py index 818498fbae..af33f92126 100644 --- a/src/sage/repl/display/fancy_repr.py +++ b/src/sage/repl/display/fancy_repr.py @@ -15,10 +15,12 @@ Representations of objects. import types from IPython.lib.pretty import ( - _safe_getattr, _baseclass_reprs, + _safe_getattr, _type_pprinters, ) +_baseclass_reprs = (object.__repr__,) + from sage.repl.display.util import format_list diff --git a/src/sage/repl/display/formatter.py b/src/sage/repl/display/formatter.py index 5eece441c6..11db26b0db 100644 --- a/src/sage/repl/display/formatter.py +++ b/src/sage/repl/display/formatter.py @@ -173,8 +173,8 @@ class SageDisplayFormatter(DisplayFormatter): sage: shell.run_cell('ipython_image') sage: shell.run_cell('get_ipython().display_formatter.format(ipython_image)') - ({u'image/png': ...'\x89PNG...', - u'text/plain': u''}, + ({'image/png': ...', + 'text/plain': ''}, {}) Test that IPython images still work even in latex output mode:: diff --git a/src/sage/repl/interpreter.py b/src/sage/repl/interpreter.py index e843486e26..780cae264d 100644 --- a/src/sage/repl/interpreter.py +++ b/src/sage/repl/interpreter.py @@ -78,7 +78,7 @@ Check that Cython source code appears in tracebacks:: dummy line ... ZeroDivisionError...Traceback (most recent call last) - in () + in ... ----> 1 Integer(1)/Integer(0) .../sage/rings/integer.pyx in sage.rings.integer.Integer...div... (.../cythonized/sage/rings/integer.c:...)() ... @@ -364,22 +364,19 @@ class SageTestShell(SageShellOverride, TerminalInteractiveShell): ################################################################### # Transformers used in the SageInputSplitter ################################################################### -from IPython.core.inputtransformer import (CoroutineInputTransformer, - StatelessInputTransformer, - _strip_prompts) +from IPython.core.inputtransformer2 import PromptStripper -@StatelessInputTransformer.wrap -def SagePreparseTransformer(line): +def SagePreparseTransformer(lines): r""" EXAMPLES:: sage: from sage.repl.interpreter import SagePreparseTransformer - sage: spt = SagePreparseTransformer() - sage: spt.push('1+1r+2.3^2.3r') - "Integer(1)+1+RealNumber('2.3')**2.3" + sage: spt = SagePreparseTransformer + sage: spt(['1+1r+2.3^2.3r']) + ["Integer(1)+1+RealNumber('2.3')**2.3"] sage: preparser(False) - sage: spt.push('2.3^2') - '2.3^2' + sage: spt(['2.3^2']) + ['2.3^2'] TESTS: @@ -400,57 +397,15 @@ def SagePreparseTransformer(line): sage: shell.quit() """ - if _do_preparse and not line.startswith('%'): - return preparse(line) - else: - return line - -@CoroutineInputTransformer.wrap -def SagePromptTransformer(): - r""" - Strip the sage:/....: prompts of Sage. - - EXAMPLES:: - - sage: from sage.repl.interpreter import SagePromptTransformer - sage: spt = SagePromptTransformer() - sage: spt.push("sage: 2 + 2") - '2 + 2' - sage: spt.push('') - '' - sage: spt.push("....: 2+2") - '2+2' - - This should strip multiple prompts: see :trac:`16297`:: - - sage: spt.push("sage: sage: 2+2") - '2+2' - sage: spt.push(" sage: ....: 2+2") - '2+2' - - The prompt contains a trailing space. Extra spaces between the - last prompt and the remainder should not be stripped:: - - sage: spt.push(" sage: ....: 2+2") - ' 2+2' - - We test that the input transformer is enabled on the Sage command - line:: - - sage: from sage.repl.interpreter import get_test_shell - sage: shell = get_test_shell() - sage: shell.run_cell('sage: a = 123') # single line - sage: shell.run_cell('sage: a = [\n... 123]') # old-style multi-line - sage: shell.run_cell('sage: a = [\n....: 123]') # new-style multi-line - - We test that :trac:`16196` is resolved:: + lines_out = [] + for line in lines: + if _do_preparse and not line.startswith('%'): + lines_out += [preparse(line)] + else: + lines_out += [line] + return lines_out - sage: shell.run_cell(' sage: 1+1') - 2 - sage: shell.quit() - """ - _sage_prompt_re = re.compile(r'^(\s*(:?sage: |\.\.\.\.: ))+') - return _strip_prompts(_sage_prompt_re) +SagePromptTransformer = PromptStripper(prompt_re=re.compile(r'^(\s*(:?sage: |\.\.\.\.: ))+')) ################### # Interface shell # @@ -612,7 +567,7 @@ def interface_shell_embed(interface): sage: shell = interface_shell_embed(gap) sage: shell.run_cell('List( [1..10], IsPrime )') [ false, true, true, false, true, false, true, false, false, false ] - + """ cfg = sage_ipython_config.copy() ipshell = InteractiveShellEmbed(config=cfg, diff --git a/src/sage/repl/ipython_extension.py b/src/sage/repl/ipython_extension.py index fd27b43fc4..a0a9f80dff 100644 --- a/src/sage/repl/ipython_extension.py +++ b/src/sage/repl/ipython_extension.py @@ -511,10 +511,8 @@ class SageCustomizations(object): from .interpreter import (SagePreparseTransformer, SagePromptTransformer) - for s in (self.shell.input_splitter, self.shell.input_transformer_manager): - s.physical_line_transforms.insert(1, SagePromptTransformer()) - s.python_line_transforms.append(SagePreparseTransformer()) - + self.shell.input_transformers_cleanup.insert(1, SagePromptTransformer) + self.shell.input_transformers_post.append(SagePreparseTransformer) class SageJupyterCustomizations(SageCustomizations): @staticmethod diff --git a/src/sage/repl/ipython_tests.py b/src/sage/repl/ipython_tests.py index d342ba7fac..ab9504337e 100644 --- a/src/sage/repl/ipython_tests.py +++ b/src/sage/repl/ipython_tests.py @@ -42,6 +42,7 @@ Next, test the pinfo magic for Cython code:: Init docstring: ...ee help(type(...)) for...signature... File: .../sage/tests/stl_vector.pyx Type: type + ... Next, test the ``pinfo`` magic for ``R`` interface code, see :trac:`26906`:: @@ -67,6 +68,7 @@ calls when you ask for the double-questionmark help, like `foo??` :: sage: shell.run_cell(u'from sage.repl.ipython_tests import dummy') sage: shell.run_cell(u'%pinfo2 dummy') Signature: dummy(argument, optional=None) + ... Source: def dummy(argument, optional=None): """ @@ -116,6 +118,7 @@ Next, test the pinfo2 magic for Cython code:: ... File: .../sage/tests/stl_vector.pyx Type: type + ... Next, test the ``pinfo2`` magic for ``R`` interface code, see :trac:`26906`:: diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 9c6ec027d0..4d3521c3e8 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -8096,13 +8096,13 @@ class ANBinaryExpr(ANDescr): decrease it before we return:: sage: import sys; sys.getrecursionlimit() - 1000 + 3000 sage: s = SymmetricFunctions(QQ).schur() sage: a=s([3,2]).expand(8)(flatten([[QQbar.zeta(3)^d for d in range(3)], [QQbar.zeta(5)^d for d in range(5)]])) sage: a.exactify(); a # long time 0 sage: sys.getrecursionlimit() - 1000 + 3000 """ import sys