From 489b2071f612d90b67afd0b5961d14ad9ff07b2b 2020-07-18 20:35:12 From: Matthias Bussonnier Date: 2020-07-18 20:35:12 Subject: [PATCH] Backport PR #12453: Allow spaces when using debug magic --- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index dc6cdf0..a7ca07b 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -467,7 +467,13 @@ python-profiler package from non-free.""") if not (args.breakpoint or args.statement or cell): self._debug_post_mortem() + elif not (args.breakpoint or cell): + # If there is no breakpoints, the line is just code to execute + self._debug_exec(line, None) else: + # Here we try to reconstruct the code from the output of + # parse_argstring. This might not work if the code has spaces + # For example this fails for `print("a b")` code = "\n".join(args.statement) if cell: code += "\n" + cell diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 877326c..d6e5d2f 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -32,6 +32,7 @@ from IPython.utils.io import capture_output from IPython.utils.tempdir import (TemporaryDirectory, TemporaryWorkingDirectory) from IPython.utils.process import find_cmd +from .test_debugger import PdbTestInput @magic.magics_class @@ -622,6 +623,18 @@ def doctest_precision(): Out[5]: '3.141593e+00' """ +def test_debug_magic(): + """Test debugging a small code with %debug + + In [1]: with PdbTestInput(['c']): + ...: %debug print("a b") #doctest: +ELLIPSIS + ...: + ... + ipdb> c + a b + In [2]: + """ + def test_psearch(): with tt.AssertPrints("dict.fromkeys"): _ip.run_cell("dict.fr*?")