##// END OF EJS Templates
SyntaxWarning in compile indicates invalid input
Min RK -
Show More
@@ -20,6 +20,7 b' import ast'
20 20 import codeop
21 21 import re
22 22 import sys
23 import warnings
23 24
24 25 from IPython.utils.py3compat import cast_unicode
25 26 from IPython.core.inputtransformer import (leading_indent,
@@ -308,14 +309,16 b' class InputSplitter(object):'
308 309
309 310 self._update_indent(lines)
310 311 try:
311 self.code = self._compile(source, symbol="exec")
312 with warnings.catch_warnings():
313 warnings.simplefilter('error', SyntaxWarning)
314 self.code = self._compile(source, symbol="exec")
312 315 # Invalid syntax can produce any of a number of different errors from
313 316 # inside the compiler, so we have to catch them all. Syntax errors
314 317 # immediately produce a 'ready' block, so the invalid Python can be
315 318 # sent to the kernel for evaluation with possible ipython
316 319 # special-syntax conversion.
317 320 except (SyntaxError, OverflowError, ValueError, TypeError,
318 MemoryError):
321 MemoryError, SyntaxWarning):
319 322 self._is_complete = True
320 323 self._is_invalid = True
321 324 else:
@@ -348,6 +348,7 b' class InputSplitterTestCase(unittest.TestCase):'
348 348 self.assertEqual(isp.check_complete("for a in range(5):"), ('incomplete', 4))
349 349 self.assertEqual(isp.check_complete("raise = 2"), ('invalid', None))
350 350 self.assertEqual(isp.check_complete("a = [1,\n2,"), ('incomplete', 0))
351 self.assertEqual(isp.check_complete("def a():\n x=1\n global x"), ('invalid', None))
351 352
352 353 class InteractiveLoopTestCase(unittest.TestCase):
353 354 """Tests for an interactive loop like a python shell.
General Comments 0
You need to be logged in to leave comments. Login now