##// END OF EJS Templates
Suppress output even when a comment follows ;. Fixes #4525.
Shashi Gowda -
Show More
@@ -26,6 +26,7 b' from __future__ import print_function'
26 26 import sys
27 27
28 28 from IPython.core.formatters import _safe_get_formatter_method
29 from IPython.core import inputsplitter
29 30 from IPython.config.configurable import Configurable
30 31 from IPython.utils import io
31 32 from IPython.utils.py3compat import builtin_mod
@@ -100,12 +101,10 b' class DisplayHook(Configurable):'
100 101 # do not print output if input ends in ';'
101 102 try:
102 103 cell = self.shell.history_manager.input_hist_parsed[self.prompt_count]
103 if cell.rstrip().endswith(';'):
104 return True
104 return inputsplitter.remove_comments(cell).rstrip().endswith(';')
105 105 except IndexError:
106 106 # some uses of ipshellembed may fail here
107 pass
108 return False
107 return False
109 108
110 109 def start_displayhook(self):
111 110 """Start the displayhook, initializing resources."""
@@ -98,13 +98,17 b' class InteractiveShellTestCase(unittest.TestCase):'
98 98 def test_dont_cache_with_semicolon(self):
99 99 "Ending a line with semicolon should not cache the returned object (GH-307)"
100 100 oldlen = len(ip.user_ns['Out'])
101 a = ip.run_cell('1;', store_history=True)
102 newlen = len(ip.user_ns['Out'])
103 self.assertEqual(oldlen, newlen)
101 for cell in ['1;', '1; #a', '1;1;']:
102 ip.run_cell(cell, store_history=True)
103 newlen = len(ip.user_ns['Out'])
104 self.assertEqual(oldlen, newlen)
105 i = 0
104 106 #also test the default caching behavior
105 ip.run_cell('1', store_history=True)
106 newlen = len(ip.user_ns['Out'])
107 self.assertEqual(oldlen+1, newlen)
107 for cell in ['1', '1 #;', '1;1']:
108 ip.run_cell(cell, store_history=True)
109 newlen = len(ip.user_ns['Out'])
110 i += 1
111 self.assertEqual(oldlen+i, newlen)
108 112
109 113 def test_In_variable(self):
110 114 "Verify that In variable grows with user input (GH-284)"
General Comments 0
You need to be logged in to leave comments. Login now