summarylogtreecommitdiffstats
path: root/sagemath-ipython7.patch
blob: 94e011771d31d06d045211d61fa7ce81bf66915e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
diff --git a/src/sage/combinat/combinatorial_map.py b/src/sage/combinat/combinatorial_map.py
index 03075615bd..0be1240a94 100644
--- a/src/sage/combinat/combinatorial_map.py
+++ b/src/sage/combinat/combinatorial_map.py
@@ -257,8 +257,8 @@ class CombinatorialMap(object):
         EXAMPLES::
 
             sage: sage.combinat.combinatorial_map.combinatorial_map = sage.combinat.combinatorial_map.combinatorial_map_wrapper
-            sage: import imp
-            sage: _ = imp.reload(sage.combinat.permutation)
+            sage: import importlib
+            sage: _ = importlib.reload(sage.combinat.permutation)
             sage: p = Permutation([1,3,2,4])
             sage: p.left_tableau.__repr__()
             'Combinatorial map: Robinson-Schensted insertion tableau'
@@ -272,8 +272,8 @@ class CombinatorialMap(object):
         EXAMPLES::
 
             sage: sage.combinat.combinatorial_map.combinatorial_map = sage.combinat.combinatorial_map.combinatorial_map_wrapper
-            sage: import imp
-            sage: _ = imp.reload(sage.combinat.permutation)
+            sage: import importlib
+            sage: _ = importlib.reload(sage.combinat.permutation)
             sage: p = Permutation([1,3,2,4])
             sage: cm = p.left_tableau; cm
             Combinatorial map: Robinson-Schensted insertion tableau
@@ -293,8 +293,8 @@ class CombinatorialMap(object):
         EXAMPLES::
 
             sage: sage.combinat.combinatorial_map.combinatorial_map = sage.combinat.combinatorial_map.combinatorial_map_wrapper
-            sage: import imp
-            sage: _ = imp.reload(sage.combinat.permutation)
+            sage: import importlib
+            sage: _ = importlib.reload(sage.combinat.permutation)
             sage: p = Permutation([1,3,2,4])
             sage: p.left_tableau #indirect doctest
             Combinatorial map: Robinson-Schensted insertion tableau
@@ -309,8 +309,8 @@ class CombinatorialMap(object):
         EXAMPLES::
 
             sage: sage.combinat.combinatorial_map.combinatorial_map = sage.combinat.combinatorial_map.combinatorial_map_wrapper
-            sage: import imp
-            sage: _ = imp.reload(sage.combinat.permutation)
+            sage: import importlib
+            sage: _ = importlib.reload(sage.combinat.permutation)
             sage: p = Permutation([1,3,2,4])
             sage: cm = type(p).left_tableau; cm
             Combinatorial map: Robinson-Schensted insertion tableau
@@ -335,8 +335,8 @@ class CombinatorialMap(object):
         EXAMPLES::
 
             sage: sage.combinat.combinatorial_map.combinatorial_map = sage.combinat.combinatorial_map.combinatorial_map_wrapper
-            sage: import imp
-            sage: _ = imp.reload(sage.combinat.permutation)
+            sage: import importlib
+            sage: _ = importlib.reload(sage.combinat.permutation)
             sage: from sage.combinat.permutation import Permutation
             sage: pi = Permutation([1,3,2])
             sage: f = pi.reverse
@@ -400,8 +400,8 @@ def combinatorial_maps_in_class(cls):
     EXAMPLES::
 
         sage: sage.combinat.combinatorial_map.combinatorial_map = sage.combinat.combinatorial_map.combinatorial_map_wrapper
-        sage: import imp
-        sage: _ = imp.reload(sage.combinat.permutation)
+        sage: import importlib
+        sage: _ = importlib.reload(sage.combinat.permutation)
         sage: from sage.combinat.combinatorial_map import combinatorial_maps_in_class
         sage: p = Permutation([1,3,2,4])
         sage: cmaps = combinatorial_maps_in_class(p)
diff --git a/src/sage/parallel/use_fork.py b/src/sage/parallel/use_fork.py
index c3b5e59fe0..7c4207901b 100644
--- a/src/sage/parallel/use_fork.py
+++ b/src/sage/parallel/use_fork.py
@@ -279,7 +279,7 @@ class p_iter_fork(object):
             sage: F._subprocess(operator.add, tmp_dir(), (1, 2))
             sage: sys.stdout = saved_stdout
         """
-        import imp, os, sys
+        import importlib, os, sys
         from sage.misc.persist import save
 
         # Make it so all stdout is sent to a file so it can
@@ -291,7 +291,7 @@ class p_iter_fork(object):
         # pid has changed (forcing a reload of
         # misc).
         import sage.misc.misc
-        imp.reload(sage.misc.misc)
+        importlib.reload(sage.misc.misc)
 
         # The pexpect interfaces (and objects defined in them) are
         # not valid.

diff --git a/src/sage/all.py b/src/sage/all.py
index c87c9372e9..72db7b85bb 100644
--- a/src/sage/all.py
+++ b/src/sage/all.py
@@ -19,7 +19,7 @@ We exclude the dependencies and check to see that there are no others
 except for the known bad apples::
 
     sage: allowed = [
-    ....:     'IPython', 'prompt_toolkit',     # sage dependencies
+    ....:     'IPython', 'prompt_toolkit', 'jedi',   # sage dependencies
     ....:     'threading', 'multiprocessing',  # doctest dependencies
     ....:     '__main__', 'sage.doctest',      # doctesting
     ....:     'signal', 'enum',                # may appear in Python 3
diff --git a/src/sage/repl/attach.py b/src/sage/repl/attach.py
index c350ec33af..4605951df2 100644
--- a/src/sage/repl/attach.py
+++ b/src/sage/repl/attach.py
@@ -249,13 +249,13 @@ def reset_load_attach_path():
         sage: reset_load_attach_path(); load_attach_path()
         ['.']
         sage: os.environ['SAGE_LOAD_ATTACH_PATH'] = '/veni/vidi:vici:'
-        sage: import imp
-        sage: imp.reload(sage.repl.attach)    # Simulate startup
+        sage: import importlib
+        sage: importlib.reload(sage.repl.attach)    # Simulate startup
         <module 'sage.repl.attach' from '...'>
         sage: load_attach_path()
         ['.', '/veni/vidi', 'vici']
         sage: del os.environ['SAGE_LOAD_ATTACH_PATH']
-        sage: imp.reload(sage.repl.preparse)    # Simulate startup
+        sage: importlib.reload(sage.repl.preparse)    # Simulate startup
         <module 'sage.repl.preparse' from '...'>
         sage: reset_load_attach_path(); load_attach_path()
         ['.']
@@ -595,12 +595,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/interpreter.py b/src/sage/repl/interpreter.py
index 5c56e6bf89..a96c350791 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)
-    <ipython-input-...> in <module>()
+    <ipython-input-...> in <module>...
     ----> 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):
         <BLANKLINE>
         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 ]
-        <ExecutionResult object at ..., execution_count=None error_before_exec=None error_in_exec=None result=[ false, true, true, false, true, false, true, false, false, false ]>
+        <ExecutionResult object at ..., execution_count=None error_before_exec=None error_in_exec=None ...result=[ 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 21d21afd3d..0c58dd1d26 100644
--- a/src/sage/repl/ipython_extension.py
+++ b/src/sage/repl/ipython_extension.py
@@ -509,10 +509,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/rings/qqbar.py b/src/sage/rings/qqbar.py
index 0dc5e1f4cc..afb3396755 100644
--- a/src/sage/rings/qqbar.py
+++ b/src/sage/rings/qqbar.py
@@ -7732,13 +7732,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
diff --git a/src/sage/repl/interface_magic.py b/src/sage/repl/interface_magic.py
index a2b9988315..15da4c0bab 100644
--- a/src/sage/repl/interface_magic.py
+++ b/src/sage/repl/interface_magic.py
@@ -260,7 +260,7 @@ class InterfaceMagic(object):
             2
             120
             sage: shell.run_cell('%%gap foo\n1+1;\n')
-            File "<string>", line unknown
+            ...File "<string>", line unknown
             SyntaxError: Interface magics have no options, got "foo"
             <BLANKLINE>
             sage: shell.run_cell('%%gap?')
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/repl/display/formatter.py b/src/sage/repl/display/formatter.py
index 5ffdb3d374..0d28873e2a 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')
             <IPython.core.display.Image object>
             sage: shell.run_cell('get_ipython().display_formatter.format(ipython_image)')
-            ({u'image/png': ...'\x89PNG...',
-              u'text/plain': u'<IPython.core.display.Image object>'},
+            ({'image/png': ...',
+              'text/plain': '<IPython.core.display.Image object>'},
             {})
 
         Test that IPython images still work even in latex output mode::