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