diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 5c48bca..34f3b72 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -20,6 +20,7 @@ import ast import codeop import re import sys +import warnings from IPython.utils.py3compat import cast_unicode from IPython.core.inputtransformer import (leading_indent, @@ -308,14 +309,16 @@ class InputSplitter(object): self._update_indent(lines) try: - self.code = self._compile(source, symbol="exec") + with warnings.catch_warnings(): + warnings.simplefilter('error', SyntaxWarning) + self.code = self._compile(source, symbol="exec") # Invalid syntax can produce any of a number of different errors from # inside the compiler, so we have to catch them all. Syntax errors # immediately produce a 'ready' block, so the invalid Python can be # sent to the kernel for evaluation with possible ipython # special-syntax conversion. except (SyntaxError, OverflowError, ValueError, TypeError, - MemoryError): + MemoryError, SyntaxWarning): self._is_complete = True self._is_invalid = True else: diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index e2ae120..c657d7f 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -348,6 +348,7 @@ class InputSplitterTestCase(unittest.TestCase): self.assertEqual(isp.check_complete("for a in range(5):"), ('incomplete', 4)) self.assertEqual(isp.check_complete("raise = 2"), ('invalid', None)) self.assertEqual(isp.check_complete("a = [1,\n2,"), ('incomplete', 0)) + self.assertEqual(isp.check_complete("def a():\n x=1\n global x"), ('invalid', None)) class InteractiveLoopTestCase(unittest.TestCase): """Tests for an interactive loop like a python shell.