From b47f7f81f1575d1866aab3f77de22c6661fdcc1f 2023-02-11 21:08:12 From: nfgf Date: 2023-02-11 21:08:12 Subject: [PATCH] Issue #13926 --- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 7b558d5..c4c3a4b 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -47,6 +47,7 @@ from IPython.utils.ipstruct import Struct from IPython.utils.module_paths import find_mod from IPython.utils.path import get_py_filename, shellglob from IPython.utils.timing import clock, clock2 +from IPython.core.displayhook import DisplayHook #----------------------------------------------------------------------------- # Magic implementation classes @@ -1461,7 +1462,10 @@ class ExecutionMagics(Magics): disp = not args.no_display with capture_output(out, err, disp) as io: self.shell.run_cell(cell) - if args.output: + if DisplayHook.semicolon_at_end_of_expression(cell): + if args.output in self.shell.user_ns: + del self.shell.user_ns[args.output] + elif args.output: self.shell.user_ns[args.output] = io def parse_breakpoint(text, current_file):