From 56fbc14c2b290a9afb5e897096598383b0d6d4ae 2015-06-03 23:14:29 From: Matthias Bussonnier Date: 2015-06-03 23:14:29 Subject: [PATCH] Fix test after rebase - fix length error and conflict import name - invert try/except where necessary - use index for token for 2.7 compat - don't deep reload some things. Closes #8321 and closes #8457 --- diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index 296d2a1..5f0fd48 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -10,12 +10,13 @@ This defines a callable class that IPython uses for `sys.displayhook`. from __future__ import print_function import sys -import io, tokenize +import io as _io +import tokenize from IPython.core.formatters import _safe_get_formatter_method from traitlets.config.configurable import Configurable from IPython.utils import io -from IPython.utils.py3compat import builtin_mod +from IPython.utils.py3compat import builtin_mod, cast_unicode_py2 from traitlets import Instance, Float from IPython.utils.warn import warn @@ -84,22 +85,23 @@ class DisplayHook(Configurable): def quiet(self): """Should we silence the display hook because of ';'?""" # do not print output if input ends in ';' - - cell = self.shell.history_manager.input_hist_parsed[self.prompt_count] - sio = io.StringIO(cell) - tokens = list(tokenize.generate_tokens(sio.readline)) - + try: - for token in reversed(tokens): - if token.type in (tokenize.ENDMARKER, tokenize.COMMENT): - continue - if (token.type == tokenize.OP) and (token.string == ';'): - return True - else: - return False + cell = cast_unicode_py2(self.shell.history_manager.input_hist_parsed[-1]) except IndexError: # some uses of ipshellembed may fail here return False + + sio = _io.StringIO(cell) + tokens = list(tokenize.generate_tokens(sio.readline)) + + for token in reversed(tokens): + if token[0] in (tokenize.ENDMARKER, tokenize.COMMENT): + continue + if (token[0] == tokenize.OP) and (token[1] == ';'): + return True + else: + return False def start_displayhook(self): """Start the displayhook, initializing resources.""" diff --git a/IPython/lib/tests/test_deepreload.py b/IPython/lib/tests/test_deepreload.py index fd6383b..2c1099c 100644 --- a/IPython/lib/tests/test_deepreload.py +++ b/IPython/lib/tests/test_deepreload.py @@ -27,7 +27,7 @@ def test_deepreload_numpy(): # Standard exclusions: 'sys', 'os.path', builtin_mod_name, '__main__', # Test-related exclusions: - 'unittest', 'UserDict', + 'unittest', 'UserDict', '_collections_abc', 'tokenize' ] # `collections` builtin shall not be reloaded to avoid failure