prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Debugging history saves both python commands and pdb commands
  <!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->
  
  ### Issue Report Checklist
  
  * [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
  * [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
  * [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
  * [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
  * [ ] Tried basic troubleshooting (if a bug/error)
      * [ ] Restarted Spyder
      * [ ] Reset preferences with ``spyder --reset``
      * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
      * [ ] Tried the other applicable steps from the Troubleshooting Guide
  * [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below
  
  
  ## Problem Description
  
  When debugging, I end up with many "s" and "n" in my debugging history, preventing me from finding what I am looking for. It would be nicer to only save python commands, or at least to have an option to do so.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `spyder/widgets/ipythonconsole/debugging.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 #
  3 # Copyright © Spyder Project Contributors
  4 # Licensed under the terms of the MIT License
  5 # (see spyder/__init__.py for details)
  6 
  7 """
  8 Widget that handles communications between a console in debugging
  9 mode and Spyder
  10 """
  11 
  12 import ast
  13 import pickle
  14 
  15 from qtpy.QtCore import Qt
  16 from qtconsole.rich_jupyter_widget import RichJupyterWidget
  17 
  18 from spyder.config.base import PICKLE_PROTOCOL
  19 from spyder.config.main import CONF
  20 from spyder.py3compat import to_text_string
  21 
  22 
  23 class DebuggingWidget(RichJupyterWidget):
  24     """
  25     Widget with the necessary attributes and methods to handle
  26     communications between a console in debugging mode and
  27     Spyder
  28     """
  29 
  30     # --- Public API --------------------------------------------------
  31     def write_to_stdin(self, line):
  32         """Send raw characters to the IPython kernel through stdin"""
  33         self.kernel_client.input(line)
  34 
  35     def set_spyder_breakpoints(self, force=False):
  36         """Set Spyder breakpoints into a debugging session"""
  37         if self._reading or force:
  38             breakpoints_dict = CONF.get('run', 'breakpoints', {})
  39 
  40             # We need to enclose pickled values in a list to be able to
  41             # send them to the kernel in Python 2
  42             serialiazed_breakpoints = [pickle.dumps(breakpoints_dict,
  43                                                     protocol=PICKLE_PROTOCOL)]
  44             breakpoints = to_text_string(serialiazed_breakpoints)
  45 
  46             cmd = u"!get_ipython().kernel._set_spyder_breakpoints({})"
  47             self.kernel_client.input(cmd.format(breakpoints))
  48 
  49     def dbg_exec_magic(self, magic, args=''):
  50         """Run an IPython magic while debugging."""
  51         code = "!get_ipython().kernel.shell.run_line_magic('{}', '{}')".format(
  52                     magic, args)
  53         self.kernel_client.input(code)
  54 
  55     def refresh_from_pdb(self, pdb_state):
  56         """
  57         Refresh Variable Explorer and Editor from a Pdb session,
  58         after running any pdb command.
  59 
  60         See publish_pdb_state and notify_spyder in spyder_kernels
  61         """
  62         if 'step' in pdb_state and 'fname' in pdb_state['step']:
  63             fname = pdb_state['step']['fname']
  64             lineno = pdb_state['step']['lineno']
  65             self.sig_pdb_step.emit(fname, lineno)
  66 
  67         if 'namespace_view' in pdb_state:
  68             self.sig_namespace_view.emit(ast.literal_eval(
  69                     pdb_state['namespace_view']))
  70 
  71         if 'var_properties' in pdb_state:
  72             self.sig_var_properties.emit(ast.literal_eval(
  73                     pdb_state['var_properties']))
  74 
  75     # ---- Private API (overrode by us) ----------------------------
  76     def _handle_input_request(self, msg):
  77         """Save history and add a %plot magic."""
  78         if self._hidden:
  79             raise RuntimeError('Request for raw input during hidden execution.')
  80 
  81         # Make sure that all output from the SUB channel has been processed
  82         # before entering readline mode.
  83         self.kernel_client.iopub_channel.flush()
  84 
  85         def callback(line):
  86             # Save history to browse it later
  87             if not (len(self._control.history) > 0
  88                     and self._control.history[-1] == line):
  89                 self._control.history.append(line)
  90 
  91             # This is the Spyder addition: add a %plot magic to display
  92             # plots while debugging
  93             if line.startswith('%plot '):
  94                 line = line.split()[-1]
  95                 code = "__spy_code__ = get_ipython().run_cell('%s')" % line
  96                 self.kernel_client.input(code)
  97             else:
  98                 self.kernel_client.input(line)
  99         if self._reading:
  100             self._reading = False
  101         self._readline(msg['content']['prompt'], callback=callback,
  102                        password=msg['content']['password'])
  103 
  104     def _event_filter_console_keypress(self, event):
  105         """Handle Key_Up/Key_Down while debugging."""
  106         key = event.key()
  107         if self._reading:
  108             self._control.current_prompt_pos = self._prompt_pos
  109             if key == Qt.Key_Up:
  110                 self._control.browse_history(backward=True)
  111                 return True
  112             elif key == Qt.Key_Down:
  113                 self._control.browse_history(backward=False)
  114                 return True
  115             elif key in (Qt.Key_Return, Qt.Key_Enter):
  116                 self._control.reset_search_pos()
  117             else:
  118                 self._control.hist_wholeline = False
  119             return super(DebuggingWidget,
  120                          self)._event_filter_console_keypress(event)
  121         else:
  122             return super(DebuggingWidget,
  123                          self)._event_filter_console_keypress(event)
  124
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/spyder/widgets/ipythonconsole/debugging.py b/spyder/widgets/ipythonconsole/debugging.py
  --- a/spyder/widgets/ipythonconsole/debugging.py
  +++ b/spyder/widgets/ipythonconsole/debugging.py
  @@ -10,6 +10,7 @@
   """
   
   import ast
  +import pdb
   import pickle
   
   from qtpy.QtCore import Qt
  @@ -86,7 +87,10 @@
               # Save history to browse it later
               if not (len(self._control.history) > 0
                       and self._control.history[-1] == line):
  -                self._control.history.append(line)
  +                # do not save pdb commands
  +                cmd = line.split(" ")[0]
  +                if "do_" + cmd not in dir(pdb.Pdb):
  +                    self._control.history.append(line)
   
               # This is the Spyder addition: add a %plot magic to display
               # plots while debugging
  
verification_info: {"golden_diff": "diff --git a/spyder/widgets/ipythonconsole/debugging.py b/spyder/widgets/ipythonconsole/debugging.py\n--- a/spyder/widgets/ipythonconsole/debugging.py\n+++ b/spyder/widgets/ipythonconsole/debugging.py\n@@ -10,6 +10,7 @@\n \"\"\"\n \n import ast\n+import pdb\n import pickle\n \n from qtpy.QtCore import Qt\n@@ -86,7 +87,10 @@\n             # Save history to browse it later\n             if not (len(self._control.history) > 0\n                     and self._control.history[-1] == line):\n-                self._control.history.append(line)\n+                # do not save pdb commands\n+                cmd = line.split(\" \")[0]\n+                if \"do_\" + cmd not in dir(pdb.Pdb):\n+                    self._control.history.append(line)\n \n             # This is the Spyder addition: add a %plot magic to display\n             # plots while debugging\n", "issue": "Debugging history saves both python commands and pdb commands\n<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->\r\n\r\n### Issue Report Checklist\r\n\r\n* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports\r\n* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice\r\n* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)\r\n* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related)\r\n* [ ] Tried basic troubleshooting (if a bug/error)\r\n    * [ ] Restarted Spyder\r\n    * [ ] Reset preferences with ``spyder --reset``\r\n    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)\r\n    * [ ] Tried the other applicable steps from the Troubleshooting Guide\r\n* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below\r\n\r\n\r\n## Problem Description\r\n\r\nWhen debugging, I end up with many \"s\" and \"n\" in my debugging history, preventing me from finding what I am looking for. It would be nicer to only save python commands, or at least to have an option to do so.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright \u00a9 Spyder Project Contributors\n# Licensed under the terms of the MIT License\n# (see spyder/__init__.py for details)\n\n\"\"\"\nWidget that handles communications between a console in debugging\nmode and Spyder\n\"\"\"\n\nimport ast\nimport pickle\n\nfrom qtpy.QtCore import Qt\nfrom qtconsole.rich_jupyter_widget import RichJupyterWidget\n\nfrom spyder.config.base import PICKLE_PROTOCOL\nfrom spyder.config.main import CONF\nfrom spyder.py3compat import to_text_string\n\n\nclass DebuggingWidget(RichJupyterWidget):\n    \"\"\"\n    Widget with the necessary attributes and methods to handle\n    communications between a console in debugging mode and\n    Spyder\n    \"\"\"\n\n    # --- Public API --------------------------------------------------\n    def write_to_stdin(self, line):\n        \"\"\"Send raw characters to the IPython kernel through stdin\"\"\"\n        self.kernel_client.input(line)\n\n    def set_spyder_breakpoints(self, force=False):\n        \"\"\"Set Spyder breakpoints into a debugging session\"\"\"\n        if self._reading or force:\n            breakpoints_dict = CONF.get('run', 'breakpoints', {})\n\n            # We need to enclose pickled values in a list to be able to\n            # send them to the kernel in Python 2\n            serialiazed_breakpoints = [pickle.dumps(breakpoints_dict,\n                                                    protocol=PICKLE_PROTOCOL)]\n            breakpoints = to_text_string(serialiazed_breakpoints)\n\n            cmd = u\"!get_ipython().kernel._set_spyder_breakpoints({})\"\n            self.kernel_client.input(cmd.format(breakpoints))\n\n    def dbg_exec_magic(self, magic, args=''):\n        \"\"\"Run an IPython magic while debugging.\"\"\"\n        code = \"!get_ipython().kernel.shell.run_line_magic('{}', '{}')\".format(\n                    magic, args)\n        self.kernel_client.input(code)\n\n    def refresh_from_pdb(self, pdb_state):\n        \"\"\"\n        Refresh Variable Explorer and Editor from a Pdb session,\n        after running any pdb command.\n\n        See publish_pdb_state and notify_spyder in spyder_kernels\n        \"\"\"\n        if 'step' in pdb_state and 'fname' in pdb_state['step']:\n            fname = pdb_state['step']['fname']\n            lineno = pdb_state['step']['lineno']\n            self.sig_pdb_step.emit(fname, lineno)\n\n        if 'namespace_view' in pdb_state:\n            self.sig_namespace_view.emit(ast.literal_eval(\n                    pdb_state['namespace_view']))\n\n        if 'var_properties' in pdb_state:\n            self.sig_var_properties.emit(ast.literal_eval(\n                    pdb_state['var_properties']))\n\n    # ---- Private API (overrode by us) ----------------------------\n    def _handle_input_request(self, msg):\n        \"\"\"Save history and add a %plot magic.\"\"\"\n        if self._hidden:\n            raise RuntimeError('Request for raw input during hidden execution.')\n\n        # Make sure that all output from the SUB channel has been processed\n        # before entering readline mode.\n        self.kernel_client.iopub_channel.flush()\n\n        def callback(line):\n            # Save history to browse it later\n            if not (len(self._control.history) > 0\n                    and self._control.history[-1] == line):\n                self._control.history.append(line)\n\n            # This is the Spyder addition: add a %plot magic to display\n            # plots while debugging\n            if line.startswith('%plot '):\n                line = line.split()[-1]\n                code = \"__spy_code__ = get_ipython().run_cell('%s')\" % line\n                self.kernel_client.input(code)\n            else:\n                self.kernel_client.input(line)\n        if self._reading:\n            self._reading = False\n        self._readline(msg['content']['prompt'], callback=callback,\n                       password=msg['content']['password'])\n\n    def _event_filter_console_keypress(self, event):\n        \"\"\"Handle Key_Up/Key_Down while debugging.\"\"\"\n        key = event.key()\n        if self._reading:\n            self._control.current_prompt_pos = self._prompt_pos\n            if key == Qt.Key_Up:\n                self._control.browse_history(backward=True)\n                return True\n            elif key == Qt.Key_Down:\n                self._control.browse_history(backward=False)\n                return True\n            elif key in (Qt.Key_Return, Qt.Key_Enter):\n                self._control.reset_search_pos()\n            else:\n                self._control.hist_wholeline = False\n            return super(DebuggingWidget,\n                         self)._event_filter_console_keypress(event)\n        else:\n            return super(DebuggingWidget,\n                         self)._event_filter_console_keypress(event)\n", "path": "spyder/widgets/ipythonconsole/debugging.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright \u00a9 Spyder Project Contributors\n# Licensed under the terms of the MIT License\n# (see spyder/__init__.py for details)\n\n\"\"\"\nWidget that handles communications between a console in debugging\nmode and Spyder\n\"\"\"\n\nimport ast\nimport pdb\nimport pickle\n\nfrom qtpy.QtCore import Qt\nfrom qtconsole.rich_jupyter_widget import RichJupyterWidget\n\nfrom spyder.config.base import PICKLE_PROTOCOL\nfrom spyder.config.main import CONF\nfrom spyder.py3compat import to_text_string\n\n\nclass DebuggingWidget(RichJupyterWidget):\n    \"\"\"\n    Widget with the necessary attributes and methods to handle\n    communications between a console in debugging mode and\n    Spyder\n    \"\"\"\n\n    # --- Public API --------------------------------------------------\n    def write_to_stdin(self, line):\n        \"\"\"Send raw characters to the IPython kernel through stdin\"\"\"\n        self.kernel_client.input(line)\n\n    def set_spyder_breakpoints(self, force=False):\n        \"\"\"Set Spyder breakpoints into a debugging session\"\"\"\n        if self._reading or force:\n            breakpoints_dict = CONF.get('run', 'breakpoints', {})\n\n            # We need to enclose pickled values in a list to be able to\n            # send them to the kernel in Python 2\n            serialiazed_breakpoints = [pickle.dumps(breakpoints_dict,\n                                                    protocol=PICKLE_PROTOCOL)]\n            breakpoints = to_text_string(serialiazed_breakpoints)\n\n            cmd = u\"!get_ipython().kernel._set_spyder_breakpoints({})\"\n            self.kernel_client.input(cmd.format(breakpoints))\n\n    def dbg_exec_magic(self, magic, args=''):\n        \"\"\"Run an IPython magic while debugging.\"\"\"\n        code = \"!get_ipython().kernel.shell.run_line_magic('{}', '{}')\".format(\n                    magic, args)\n        self.kernel_client.input(code)\n\n    def refresh_from_pdb(self, pdb_state):\n        \"\"\"\n        Refresh Variable Explorer and Editor from a Pdb session,\n        after running any pdb command.\n\n        See publish_pdb_state and notify_spyder in spyder_kernels\n        \"\"\"\n        if 'step' in pdb_state and 'fname' in pdb_state['step']:\n            fname = pdb_state['step']['fname']\n            lineno = pdb_state['step']['lineno']\n            self.sig_pdb_step.emit(fname, lineno)\n\n        if 'namespace_view' in pdb_state:\n            self.sig_namespace_view.emit(ast.literal_eval(\n                    pdb_state['namespace_view']))\n\n        if 'var_properties' in pdb_state:\n            self.sig_var_properties.emit(ast.literal_eval(\n                    pdb_state['var_properties']))\n\n    # ---- Private API (overrode by us) ----------------------------\n    def _handle_input_request(self, msg):\n        \"\"\"Save history and add a %plot magic.\"\"\"\n        if self._hidden:\n            raise RuntimeError('Request for raw input during hidden execution.')\n\n        # Make sure that all output from the SUB channel has been processed\n        # before entering readline mode.\n        self.kernel_client.iopub_channel.flush()\n\n        def callback(line):\n            # Save history to browse it later\n            if not (len(self._control.history) > 0\n                    and self._control.history[-1] == line):\n                # do not save pdb commands\n                cmd = line.split(\" \")[0]\n                if \"do_\" + cmd not in dir(pdb.Pdb):\n                    self._control.history.append(line)\n\n            # This is the Spyder addition: add a %plot magic to display\n            # plots while debugging\n            if line.startswith('%plot '):\n                line = line.split()[-1]\n                code = \"__spy_code__ = get_ipython().run_cell('%s')\" % line\n                self.kernel_client.input(code)\n            else:\n                self.kernel_client.input(line)\n        if self._reading:\n            self._reading = False\n        self._readline(msg['content']['prompt'], callback=callback,\n                       password=msg['content']['password'])\n\n    def _event_filter_console_keypress(self, event):\n        \"\"\"Handle Key_Up/Key_Down while debugging.\"\"\"\n        key = event.key()\n        if self._reading:\n            self._control.current_prompt_pos = self._prompt_pos\n            if key == Qt.Key_Up:\n                self._control.browse_history(backward=True)\n                return True\n            elif key == Qt.Key_Down:\n                self._control.browse_history(backward=False)\n                return True\n            elif key in (Qt.Key_Return, Qt.Key_Enter):\n                self._control.reset_search_pos()\n            else:\n                self._control.hist_wholeline = False\n            return super(DebuggingWidget,\n                         self)._event_filter_console_keypress(event)\n        else:\n            return super(DebuggingWidget,\n                         self)._event_filter_console_keypress(event)\n", "path": "spyder/widgets/ipythonconsole/debugging.py"}]}