Show More
@@ -10,12 +10,13 b' This defines a callable class that IPython uses for `sys.displayhook`.' | |||
|
10 | 10 | from __future__ import print_function |
|
11 | 11 | |
|
12 | 12 | import sys |
|
13 |
import io |
|
|
13 | import io as _io | |
|
14 | import tokenize | |
|
14 | 15 | |
|
15 | 16 | from IPython.core.formatters import _safe_get_formatter_method |
|
16 | 17 | from traitlets.config.configurable import Configurable |
|
17 | 18 | from IPython.utils import io |
|
18 | from IPython.utils.py3compat import builtin_mod | |
|
19 | from IPython.utils.py3compat import builtin_mod, cast_unicode_py2 | |
|
19 | 20 | from traitlets import Instance, Float |
|
20 | 21 | from IPython.utils.warn import warn |
|
21 | 22 | |
@@ -84,22 +85,23 b' class DisplayHook(Configurable):' | |||
|
84 | 85 | def quiet(self): |
|
85 | 86 | """Should we silence the display hook because of ';'?""" |
|
86 | 87 | # do not print output if input ends in ';' |
|
87 | ||
|
88 | cell = self.shell.history_manager.input_hist_parsed[self.prompt_count] | |
|
89 | sio = io.StringIO(cell) | |
|
90 | tokens = list(tokenize.generate_tokens(sio.readline)) | |
|
91 | ||
|
88 | ||
|
92 | 89 | try: |
|
93 | for token in reversed(tokens): | |
|
94 | if token.type in (tokenize.ENDMARKER, tokenize.COMMENT): | |
|
95 | continue | |
|
96 | if (token.type == tokenize.OP) and (token.string == ';'): | |
|
97 | return True | |
|
98 | else: | |
|
99 | return False | |
|
90 | cell = cast_unicode_py2(self.shell.history_manager.input_hist_parsed[-1]) | |
|
100 | 91 | except IndexError: |
|
101 | 92 | # some uses of ipshellembed may fail here |
|
102 | 93 | return False |
|
94 | ||
|
95 | sio = _io.StringIO(cell) | |
|
96 | tokens = list(tokenize.generate_tokens(sio.readline)) | |
|
97 | ||
|
98 | for token in reversed(tokens): | |
|
99 | if token[0] in (tokenize.ENDMARKER, tokenize.COMMENT): | |
|
100 | continue | |
|
101 | if (token[0] == tokenize.OP) and (token[1] == ';'): | |
|
102 | return True | |
|
103 | else: | |
|
104 | return False | |
|
103 | 105 | |
|
104 | 106 | def start_displayhook(self): |
|
105 | 107 | """Start the displayhook, initializing resources.""" |
@@ -27,7 +27,7 b' def test_deepreload_numpy():' | |||
|
27 | 27 | # Standard exclusions: |
|
28 | 28 | 'sys', 'os.path', builtin_mod_name, '__main__', |
|
29 | 29 | # Test-related exclusions: |
|
30 | 'unittest', 'UserDict', | |
|
30 | 'unittest', 'UserDict', '_collections_abc', 'tokenize' | |
|
31 | 31 | ] |
|
32 | 32 | |
|
33 | 33 | # `collections` builtin shall not be reloaded to avoid failure |
General Comments 0
You need to be logged in to leave comments.
Login now