From 5b6fe626f21e8066ed7db71ee2315da17fa6839e 2018-02-12 15:11:37 From: Thomas Kluyver Date: 2018-02-12 15:11:37 Subject: [PATCH] Merge pull request #11005 from ipython/auto-backport-of-pr-10993 Backport PR #10993 on branch 5.x --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 41b2704..542f4c9 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2626,6 +2626,8 @@ class InteractiveShell(SingletonConfigurable): result.execution_count = self.execution_count def error_before_exec(value): + if store_history: + self.execution_count += 1 result.error_before_exec = value self.last_execution_succeeded = False return result @@ -2689,14 +2691,10 @@ class InteractiveShell(SingletonConfigurable): return error_before_exec(e) except IndentationError as e: self.showindentationerror() - if store_history: - self.execution_count += 1 return error_before_exec(e) except (OverflowError, SyntaxError, ValueError, TypeError, MemoryError) as e: self.showsyntaxerror() - if store_history: - self.execution_count += 1 return error_before_exec(e) # Apply AST transformations @@ -2704,8 +2702,6 @@ class InteractiveShell(SingletonConfigurable): code_ast = self.transform_ast(code_ast) except InputRejected as e: self.showtraceback() - if store_history: - self.execution_count += 1 return error_before_exec(e) # Give the displayhook a reference to our ExecutionResult so it diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index db22c15..5765eae 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -948,3 +948,14 @@ def wrn(): with tt.AssertNotPrints("I AM A WARNING"): ip.run_cell("wrn()") ip.run_cell("del wrn") + + +def test_custom_exc_count(): + hook = mock.Mock(return_value=None) + ip.set_custom_exc((SyntaxError,), hook) + before = ip.execution_count + ip.run_cell("def foo()", store_history=True) + # restore default excepthook + ip.set_custom_exc((), None) + nt.assert_equal(hook.call_count, 1) + nt.assert_equal(ip.execution_count, before + 1)