From c114093a427b0dd22f3790debb83f528ba6a6a37 2015-07-11 02:39:30 From: Min RK Date: 2015-07-11 02:39:30 Subject: [PATCH] Merge pull request #8620 from takluyver/i8618 Fix suppression of exception chaining with 'raise ... from None' --- diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index c823d76..25815c9 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -173,6 +173,13 @@ except Exception as e: raise KeyError('uh') """ + SUPPRESS_CHAINING_CODE = """ +try: + 1/0 +except Exception: + raise ValueError("Yikes") from None + """ + def test_direct_cause_error(self): if PY3: with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): @@ -182,3 +189,9 @@ except Exception as e: if PY3: with tt.AssertPrints(["KeyError", "NameError", "During handling"]): ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE) + + def test_suppress_exception_chaining(self): + if PY3: + with tt.AssertNotPrints("ZeroDivisionError"), \ + tt.AssertPrints("ValueError", suppress=False): + ip.run_cell(self.SUPPRESS_CHAINING_CODE) diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 34908cd..42bca4a 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -985,6 +985,8 @@ class VerboseTB(TBTools): cause = getattr(exception_value, '__cause__', None) if cause: return cause + if getattr(exception_value, '__suppress_context__', False): + return None return getattr(exception_value, '__context__', None) chained_evalue = get_chained_exception(evalue)