##// END OF EJS Templates
push() now swallows syntax errors and immediately produces a 'ready'...
Fernando Perez -
Show More
@@ -179,14 +179,21 b' class BlockBreaker(object):'
179 # exception is raised in compilation, we don't mislead by having
179 # exception is raised in compilation, we don't mislead by having
180 # inconsistent code/source attributes.
180 # inconsistent code/source attributes.
181 self.code, self.is_complete = None, None
181 self.code, self.is_complete = None, None
182 self.code = self.compile(source)
182 try:
183 # Compilation didn't produce any exceptions (though it may not have
183 self.code = self.compile(source)
184 # given a complete code object)
184 # Invalid syntax can produce any of a number of different errors from
185 if self.code is None:
185 # inside the compiler, so we have to catch them all. Syntax errors
186 self.is_complete = False
186 # immediately produce a 'ready' block, so the invalid Python can be
187 else:
187 # sent to the kernel for evaluation with possible ipython
188 # special-syntax conversion.
189 except (SyntaxError, OverflowError, ValueError, TypeError, MemoryError):
188 self.is_complete = True
190 self.is_complete = True
189 self._update_indent(lines)
191 else:
192 # Compilation didn't produce any exceptions (though it may not have
193 # given a complete code object)
194 self.is_complete = self.code is not None
195 self._update_indent(lines)
196
190 return self.is_complete
197 return self.is_complete
191
198
192 def interactive_block_ready(self):
199 def interactive_block_ready(self):
@@ -181,3 +181,11 b' class BlockBreakerTestCase(unittest.TestCase):'
181 self.assertFalse(bb.interactive_block_ready())
181 self.assertFalse(bb.interactive_block_ready())
182 bb.push('')
182 bb.push('')
183 self.assertTrue(bb.interactive_block_ready())
183 self.assertTrue(bb.interactive_block_ready())
184
185 def test_syntax_error(self):
186 bb = self.bb
187 # Syntax errors immediately produce a 'ready' block, so the invalid
188 # Python can be sent to the kernel for evaluation with possible ipython
189 # special-syntax conversion.
190 bb.push('run foo')
191 self.assertTrue(bb.interactive_block_ready())
General Comments 0
You need to be logged in to leave comments. Login now