From 1932dc8078323a2793d2d9e5c3a4bc7af80747e3 2016-04-04 18:00:17 From: Thomas Kluyver Date: 2016-04-04 18:00:17 Subject: [PATCH] Simplify code with a context manager --- diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index 3a5b1a3..0383b4e 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -344,13 +344,10 @@ class TerminalInteractiveShell(InteractiveShell): self.showtraceback() else: try: - f = open(err.filename) - try: + with open(err.filename) as f: # This should be inside a display_trap block and I # think it is. sys.displayhook(f.read()) - finally: - f.close() except: self.showtraceback()