prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  added %matplotlib --list so backends are easily visible
  linked to #8444 adding --list argument to show the available backends
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `IPython/core/magics/pylab.py`
  Content:
  ```
  1 """Implementation of magic functions for matplotlib/pylab support.
  2 """
  3 from __future__ import print_function
  4 #-----------------------------------------------------------------------------
  5 #  Copyright (c) 2012 The IPython Development Team.
  6 #
  7 #  Distributed under the terms of the Modified BSD License.
  8 #
  9 #  The full license is in the file COPYING.txt, distributed with this software.
  10 #-----------------------------------------------------------------------------
  11 
  12 #-----------------------------------------------------------------------------
  13 # Imports
  14 #-----------------------------------------------------------------------------
  15 
  16 # Our own packages
  17 from traitlets.config.application import Application
  18 from IPython.core import magic_arguments
  19 from IPython.core.magic import Magics, magics_class, line_magic
  20 from IPython.testing.skipdoctest import skip_doctest
  21 from IPython.utils.warn import warn
  22 from IPython.core.pylabtools import backends
  23 
  24 #-----------------------------------------------------------------------------
  25 # Magic implementation classes
  26 #-----------------------------------------------------------------------------
  27 
  28 magic_gui_arg = magic_arguments.argument(
  29         'gui', nargs='?',
  30         help="""Name of the matplotlib backend to use %s.
  31         If given, the corresponding matplotlib backend is used,
  32         otherwise it will be matplotlib's default
  33         (which you can set in your matplotlib config file).
  34         """ % str(tuple(sorted(backends.keys())))
  35 )
  36 
  37 
  38 @magics_class
  39 class PylabMagics(Magics):
  40     """Magics related to matplotlib's pylab support"""
  41     
  42     @skip_doctest
  43     @line_magic
  44     @magic_arguments.magic_arguments()
  45     @magic_gui_arg
  46     def matplotlib(self, line=''):
  47         """Set up matplotlib to work interactively.
  48         
  49         This function lets you activate matplotlib interactive support
  50         at any point during an IPython session. It does not import anything
  51         into the interactive namespace.
  52         
  53         If you are using the inline matplotlib backend in the IPython Notebook
  54         you can set which figure formats are enabled using the following::
  55         
  56             In [1]: from IPython.display import set_matplotlib_formats
  57             
  58             In [2]: set_matplotlib_formats('pdf', 'svg')
  59 
  60         The default for inline figures sets `bbox_inches` to 'tight'. This can
  61         cause discrepancies between the displayed image and the identical
  62         image created using `savefig`. This behavior can be disabled using the
  63         `%config` magic::
  64             
  65             In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
  66 
  67         In addition, see the docstring of
  68         `IPython.display.set_matplotlib_formats` and
  69         `IPython.display.set_matplotlib_close` for more information on
  70         changing additional behaviors of the inline backend.
  71 
  72         Examples
  73         --------
  74         To enable the inline backend for usage with the IPython Notebook::
  75         
  76             In [1]: %matplotlib inline
  77 
  78         In this case, where the matplotlib default is TkAgg::
  79 
  80             In [2]: %matplotlib
  81             Using matplotlib backend: TkAgg
  82 
  83         But you can explicitly request a different GUI backend::
  84 
  85             In [3]: %matplotlib qt
  86         """
  87         args = magic_arguments.parse_argstring(self.matplotlib, line)
  88         gui, backend = self.shell.enable_matplotlib(args.gui)
  89         self._show_matplotlib_backend(args.gui, backend)
  90 
  91     @skip_doctest
  92     @line_magic
  93     @magic_arguments.magic_arguments()
  94     @magic_arguments.argument(
  95         '--no-import-all', action='store_true', default=None,
  96         help="""Prevent IPython from performing ``import *`` into the interactive namespace.
  97         
  98         You can govern the default behavior of this flag with the
  99         InteractiveShellApp.pylab_import_all configurable.
  100         """
  101     )
  102     @magic_gui_arg
  103     def pylab(self, line=''):
  104         """Load numpy and matplotlib to work interactively.
  105 
  106         This function lets you activate pylab (matplotlib, numpy and
  107         interactive support) at any point during an IPython session.
  108         
  109         %pylab makes the following imports::
  110         
  111             import numpy
  112             import matplotlib
  113             from matplotlib import pylab, mlab, pyplot
  114             np = numpy
  115             plt = pyplot
  116             
  117             from IPython.display import display
  118             from IPython.core.pylabtools import figsize, getfigs
  119             
  120             from pylab import *
  121             from numpy import *
  122 
  123         If you pass `--no-import-all`, the last two `*` imports will be excluded.
  124         
  125         See the %matplotlib magic for more details about activating matplotlib
  126         without affecting the interactive namespace.
  127         """
  128         args = magic_arguments.parse_argstring(self.pylab, line)
  129         if args.no_import_all is None:
  130             # get default from Application
  131             if Application.initialized():
  132                 app = Application.instance()
  133                 try:
  134                     import_all = app.pylab_import_all
  135                 except AttributeError:
  136                     import_all = True
  137             else:
  138                 # nothing specified, no app - default True
  139                 import_all = True
  140         else:
  141             # invert no-import flag
  142             import_all = not args.no_import_all
  143 
  144         gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
  145         self._show_matplotlib_backend(args.gui, backend)
  146         print ("Populating the interactive namespace from numpy and matplotlib")
  147         if clobbered:
  148             warn("pylab import has clobbered these variables: %s"  % clobbered +
  149             "\n`%matplotlib` prevents importing * from pylab and numpy"
  150             )
  151     
  152     def _show_matplotlib_backend(self, gui, backend):
  153         """show matplotlib message backend message"""
  154         if not gui or gui == 'auto':
  155             print("Using matplotlib backend: %s" % backend)
  156
  ```
  --- 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/IPython/core/magics/pylab.py b/IPython/core/magics/pylab.py
  --- a/IPython/core/magics/pylab.py
  +++ b/IPython/core/magics/pylab.py
  @@ -42,6 +42,8 @@
       @skip_doctest
       @line_magic
       @magic_arguments.magic_arguments()
  +    @magic_arguments.argument('-l', '--list', action='store_true',
  +                              help='Show available matplotlib backends')
       @magic_gui_arg
       def matplotlib(self, line=''):
           """Set up matplotlib to work interactively.
  @@ -83,10 +85,20 @@
           But you can explicitly request a different GUI backend::
   
               In [3]: %matplotlib qt
  +
  +        You can list the available backends using the -l/--list option
  +
  +           In [4]: %matplotlib --list
  +           Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg',
  +            'gtk', 'tk', 'inline']
           """
           args = magic_arguments.parse_argstring(self.matplotlib, line)
  -        gui, backend = self.shell.enable_matplotlib(args.gui)
  -        self._show_matplotlib_backend(args.gui, backend)
  +        if args.list:
  +            backends_list = list(backends.keys())
  +            print("Available matplotlib backends: %s" % backends_list)
  +        else:
  +            gui, backend = self.shell.enable_matplotlib(args.gui)
  +            self._show_matplotlib_backend(args.gui, backend)
   
       @skip_doctest
       @line_magic
  
verification_info: {"golden_diff": "diff --git a/IPython/core/magics/pylab.py b/IPython/core/magics/pylab.py\n--- a/IPython/core/magics/pylab.py\n+++ b/IPython/core/magics/pylab.py\n@@ -42,6 +42,8 @@\n     @skip_doctest\n     @line_magic\n     @magic_arguments.magic_arguments()\n+    @magic_arguments.argument('-l', '--list', action='store_true',\n+                              help='Show available matplotlib backends')\n     @magic_gui_arg\n     def matplotlib(self, line=''):\n         \"\"\"Set up matplotlib to work interactively.\n@@ -83,10 +85,20 @@\n         But you can explicitly request a different GUI backend::\n \n             In [3]: %matplotlib qt\n+\n+        You can list the available backends using the -l/--list option\n+\n+           In [4]: %matplotlib --list\n+           Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg',\n+            'gtk', 'tk', 'inline']\n         \"\"\"\n         args = magic_arguments.parse_argstring(self.matplotlib, line)\n-        gui, backend = self.shell.enable_matplotlib(args.gui)\n-        self._show_matplotlib_backend(args.gui, backend)\n+        if args.list:\n+            backends_list = list(backends.keys())\n+            print(\"Available matplotlib backends: %s\" % backends_list)\n+        else:\n+            gui, backend = self.shell.enable_matplotlib(args.gui)\n+            self._show_matplotlib_backend(args.gui, backend)\n \n     @skip_doctest\n     @line_magic\n", "issue": "added %matplotlib --list so backends are easily visible\nlinked to #8444 adding --list argument to show the available backends\n\n", "before_files": [{"content": "\"\"\"Implementation of magic functions for matplotlib/pylab support.\n\"\"\"\nfrom __future__ import print_function\n#-----------------------------------------------------------------------------\n#  Copyright (c) 2012 The IPython Development Team.\n#\n#  Distributed under the terms of the Modified BSD License.\n#\n#  The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\n\n# Our own packages\nfrom traitlets.config.application import Application\nfrom IPython.core import magic_arguments\nfrom IPython.core.magic import Magics, magics_class, line_magic\nfrom IPython.testing.skipdoctest import skip_doctest\nfrom IPython.utils.warn import warn\nfrom IPython.core.pylabtools import backends\n\n#-----------------------------------------------------------------------------\n# Magic implementation classes\n#-----------------------------------------------------------------------------\n\nmagic_gui_arg = magic_arguments.argument(\n        'gui', nargs='?',\n        help=\"\"\"Name of the matplotlib backend to use %s.\n        If given, the corresponding matplotlib backend is used,\n        otherwise it will be matplotlib's default\n        (which you can set in your matplotlib config file).\n        \"\"\" % str(tuple(sorted(backends.keys())))\n)\n\n\n@magics_class\nclass PylabMagics(Magics):\n    \"\"\"Magics related to matplotlib's pylab support\"\"\"\n    \n    @skip_doctest\n    @line_magic\n    @magic_arguments.magic_arguments()\n    @magic_gui_arg\n    def matplotlib(self, line=''):\n        \"\"\"Set up matplotlib to work interactively.\n        \n        This function lets you activate matplotlib interactive support\n        at any point during an IPython session. It does not import anything\n        into the interactive namespace.\n        \n        If you are using the inline matplotlib backend in the IPython Notebook\n        you can set which figure formats are enabled using the following::\n        \n            In [1]: from IPython.display import set_matplotlib_formats\n            \n            In [2]: set_matplotlib_formats('pdf', 'svg')\n\n        The default for inline figures sets `bbox_inches` to 'tight'. This can\n        cause discrepancies between the displayed image and the identical\n        image created using `savefig`. This behavior can be disabled using the\n        `%config` magic::\n            \n            In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}\n\n        In addition, see the docstring of\n        `IPython.display.set_matplotlib_formats` and\n        `IPython.display.set_matplotlib_close` for more information on\n        changing additional behaviors of the inline backend.\n\n        Examples\n        --------\n        To enable the inline backend for usage with the IPython Notebook::\n        \n            In [1]: %matplotlib inline\n\n        In this case, where the matplotlib default is TkAgg::\n\n            In [2]: %matplotlib\n            Using matplotlib backend: TkAgg\n\n        But you can explicitly request a different GUI backend::\n\n            In [3]: %matplotlib qt\n        \"\"\"\n        args = magic_arguments.parse_argstring(self.matplotlib, line)\n        gui, backend = self.shell.enable_matplotlib(args.gui)\n        self._show_matplotlib_backend(args.gui, backend)\n\n    @skip_doctest\n    @line_magic\n    @magic_arguments.magic_arguments()\n    @magic_arguments.argument(\n        '--no-import-all', action='store_true', default=None,\n        help=\"\"\"Prevent IPython from performing ``import *`` into the interactive namespace.\n        \n        You can govern the default behavior of this flag with the\n        InteractiveShellApp.pylab_import_all configurable.\n        \"\"\"\n    )\n    @magic_gui_arg\n    def pylab(self, line=''):\n        \"\"\"Load numpy and matplotlib to work interactively.\n\n        This function lets you activate pylab (matplotlib, numpy and\n        interactive support) at any point during an IPython session.\n        \n        %pylab makes the following imports::\n        \n            import numpy\n            import matplotlib\n            from matplotlib import pylab, mlab, pyplot\n            np = numpy\n            plt = pyplot\n            \n            from IPython.display import display\n            from IPython.core.pylabtools import figsize, getfigs\n            \n            from pylab import *\n            from numpy import *\n\n        If you pass `--no-import-all`, the last two `*` imports will be excluded.\n        \n        See the %matplotlib magic for more details about activating matplotlib\n        without affecting the interactive namespace.\n        \"\"\"\n        args = magic_arguments.parse_argstring(self.pylab, line)\n        if args.no_import_all is None:\n            # get default from Application\n            if Application.initialized():\n                app = Application.instance()\n                try:\n                    import_all = app.pylab_import_all\n                except AttributeError:\n                    import_all = True\n            else:\n                # nothing specified, no app - default True\n                import_all = True\n        else:\n            # invert no-import flag\n            import_all = not args.no_import_all\n\n        gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)\n        self._show_matplotlib_backend(args.gui, backend)\n        print (\"Populating the interactive namespace from numpy and matplotlib\")\n        if clobbered:\n            warn(\"pylab import has clobbered these variables: %s\"  % clobbered +\n            \"\\n`%matplotlib` prevents importing * from pylab and numpy\"\n            )\n    \n    def _show_matplotlib_backend(self, gui, backend):\n        \"\"\"show matplotlib message backend message\"\"\"\n        if not gui or gui == 'auto':\n            print(\"Using matplotlib backend: %s\" % backend)\n", "path": "IPython/core/magics/pylab.py"}], "after_files": [{"content": "\"\"\"Implementation of magic functions for matplotlib/pylab support.\n\"\"\"\nfrom __future__ import print_function\n#-----------------------------------------------------------------------------\n#  Copyright (c) 2012 The IPython Development Team.\n#\n#  Distributed under the terms of the Modified BSD License.\n#\n#  The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\n\n# Our own packages\nfrom traitlets.config.application import Application\nfrom IPython.core import magic_arguments\nfrom IPython.core.magic import Magics, magics_class, line_magic\nfrom IPython.testing.skipdoctest import skip_doctest\nfrom IPython.utils.warn import warn\nfrom IPython.core.pylabtools import backends\n\n#-----------------------------------------------------------------------------\n# Magic implementation classes\n#-----------------------------------------------------------------------------\n\nmagic_gui_arg = magic_arguments.argument(\n        'gui', nargs='?',\n        help=\"\"\"Name of the matplotlib backend to use %s.\n        If given, the corresponding matplotlib backend is used,\n        otherwise it will be matplotlib's default\n        (which you can set in your matplotlib config file).\n        \"\"\" % str(tuple(sorted(backends.keys())))\n)\n\n\n@magics_class\nclass PylabMagics(Magics):\n    \"\"\"Magics related to matplotlib's pylab support\"\"\"\n    \n    @skip_doctest\n    @line_magic\n    @magic_arguments.magic_arguments()\n    @magic_arguments.argument('-l', '--list', action='store_true',\n                              help='Show available matplotlib backends')\n    @magic_gui_arg\n    def matplotlib(self, line=''):\n        \"\"\"Set up matplotlib to work interactively.\n        \n        This function lets you activate matplotlib interactive support\n        at any point during an IPython session. It does not import anything\n        into the interactive namespace.\n        \n        If you are using the inline matplotlib backend in the IPython Notebook\n        you can set which figure formats are enabled using the following::\n        \n            In [1]: from IPython.display import set_matplotlib_formats\n            \n            In [2]: set_matplotlib_formats('pdf', 'svg')\n\n        The default for inline figures sets `bbox_inches` to 'tight'. This can\n        cause discrepancies between the displayed image and the identical\n        image created using `savefig`. This behavior can be disabled using the\n        `%config` magic::\n            \n            In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}\n\n        In addition, see the docstring of\n        `IPython.display.set_matplotlib_formats` and\n        `IPython.display.set_matplotlib_close` for more information on\n        changing additional behaviors of the inline backend.\n\n        Examples\n        --------\n        To enable the inline backend for usage with the IPython Notebook::\n        \n            In [1]: %matplotlib inline\n\n        In this case, where the matplotlib default is TkAgg::\n\n            In [2]: %matplotlib\n            Using matplotlib backend: TkAgg\n\n        But you can explicitly request a different GUI backend::\n\n            In [3]: %matplotlib qt\n\n        You can list the available backends using the -l/--list option\n\n           In [4]: %matplotlib --list\n           Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg',\n            'gtk', 'tk', 'inline']\n        \"\"\"\n        args = magic_arguments.parse_argstring(self.matplotlib, line)\n        if args.list:\n            backends_list = list(backends.keys())\n            print(\"Available matplotlib backends: %s\" % backends_list)\n        else:\n            gui, backend = self.shell.enable_matplotlib(args.gui)\n            self._show_matplotlib_backend(args.gui, backend)\n\n    @skip_doctest\n    @line_magic\n    @magic_arguments.magic_arguments()\n    @magic_arguments.argument(\n        '--no-import-all', action='store_true', default=None,\n        help=\"\"\"Prevent IPython from performing ``import *`` into the interactive namespace.\n        \n        You can govern the default behavior of this flag with the\n        InteractiveShellApp.pylab_import_all configurable.\n        \"\"\"\n    )\n    @magic_gui_arg\n    def pylab(self, line=''):\n        \"\"\"Load numpy and matplotlib to work interactively.\n\n        This function lets you activate pylab (matplotlib, numpy and\n        interactive support) at any point during an IPython session.\n        \n        %pylab makes the following imports::\n        \n            import numpy\n            import matplotlib\n            from matplotlib import pylab, mlab, pyplot\n            np = numpy\n            plt = pyplot\n            \n            from IPython.display import display\n            from IPython.core.pylabtools import figsize, getfigs\n            \n            from pylab import *\n            from numpy import *\n\n        If you pass `--no-import-all`, the last two `*` imports will be excluded.\n        \n        See the %matplotlib magic for more details about activating matplotlib\n        without affecting the interactive namespace.\n        \"\"\"\n        args = magic_arguments.parse_argstring(self.pylab, line)\n        if args.no_import_all is None:\n            # get default from Application\n            if Application.initialized():\n                app = Application.instance()\n                try:\n                    import_all = app.pylab_import_all\n                except AttributeError:\n                    import_all = True\n            else:\n                # nothing specified, no app - default True\n                import_all = True\n        else:\n            # invert no-import flag\n            import_all = not args.no_import_all\n\n        gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)\n        self._show_matplotlib_backend(args.gui, backend)\n        print (\"Populating the interactive namespace from numpy and matplotlib\")\n        if clobbered:\n            warn(\"pylab import has clobbered these variables: %s\"  % clobbered +\n            \"\\n`%matplotlib` prevents importing * from pylab and numpy\"\n            )\n    \n    def _show_matplotlib_backend(self, gui, backend):\n        \"\"\"show matplotlib message backend message\"\"\"\n        if not gui or gui == 'auto':\n            print(\"Using matplotlib backend: %s\" % backend)\n", "path": "IPython/core/magics/pylab.py"}]}