robot-piglet 10 месяцев назад
Родитель
Сommit
ebf1daa4c4

+ 3 - 3
contrib/python/ipython/py3/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Metadata-Version: 2.1
 Name: ipython
 Name: ipython
-Version: 8.23.0
+Version: 8.24.0
 Summary: IPython: Productive Interactive Computing
 Summary: IPython: Productive Interactive Computing
 Author: The IPython Development Team
 Author: The IPython Development Team
 Author-email: ipython-dev@python.org
 Author-email: ipython-dev@python.org
@@ -34,7 +34,7 @@ Requires-Dist: pygments >=2.4.0
 Requires-Dist: stack-data
 Requires-Dist: stack-data
 Requires-Dist: traitlets >=5.13.0
 Requires-Dist: traitlets >=5.13.0
 Requires-Dist: exceptiongroup ; python_version < "3.11"
 Requires-Dist: exceptiongroup ; python_version < "3.11"
-Requires-Dist: typing-extensions ; python_version < "3.12"
+Requires-Dist: typing-extensions >=4.6 ; python_version < "3.12"
 Requires-Dist: pexpect >4.3 ; sys_platform != "win32" and sys_platform != "emscripten"
 Requires-Dist: pexpect >4.3 ; sys_platform != "win32" and sys_platform != "emscripten"
 Requires-Dist: colorama ; sys_platform == "win32"
 Requires-Dist: colorama ; sys_platform == "win32"
 Provides-Extra: all
 Provides-Extra: all
@@ -71,7 +71,7 @@ Provides-Extra: qtconsole
 Requires-Dist: qtconsole ; extra == 'qtconsole'
 Requires-Dist: qtconsole ; extra == 'qtconsole'
 Provides-Extra: terminal
 Provides-Extra: terminal
 Provides-Extra: test
 Provides-Extra: test
-Requires-Dist: pytest <8 ; extra == 'test'
+Requires-Dist: pytest ; extra == 'test'
 Requires-Dist: pytest-asyncio <0.22 ; extra == 'test'
 Requires-Dist: pytest-asyncio <0.22 ; extra == 'test'
 Requires-Dist: testpath ; extra == 'test'
 Requires-Dist: testpath ; extra == 'test'
 Requires-Dist: pickleshare ; extra == 'test'
 Requires-Dist: pickleshare ; extra == 'test'

+ 38 - 48
contrib/python/ipython/py3/IPython/core/debugger.py

@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 """
 """
 Pdb debugger class.
 Pdb debugger class.
 
 
@@ -101,17 +100,25 @@ All the changes since then are under the same license as IPython.
 #
 #
 #*****************************************************************************
 #*****************************************************************************
 
 
+from __future__ import annotations
+
 import inspect
 import inspect
 import linecache
 import linecache
-import sys
-import re
 import os
 import os
+import re
+import sys
+from contextlib import contextmanager
+from functools import lru_cache
 
 
 from IPython import get_ipython
 from IPython import get_ipython
-from contextlib import contextmanager
-from IPython.utils import PyColorize
-from IPython.utils import coloransi, py3compat
 from IPython.core.excolors import exception_colors
 from IPython.core.excolors import exception_colors
+from IPython.utils import PyColorize, coloransi, py3compat
+
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+    # otherwise circular import
+    from IPython.core.interactiveshell import InteractiveShell
 
 
 # skip module docstests
 # skip module docstests
 __skip_doctest__ = True
 __skip_doctest__ = True
@@ -149,16 +156,10 @@ def BdbQuit_excepthook(et, ev, tb, excepthook=None):
     parameter.
     parameter.
     """
     """
     raise ValueError(
     raise ValueError(
-        "`BdbQuit_excepthook` is deprecated since version 5.1",
+        "`BdbQuit_excepthook` is deprecated since version 5.1. It is still arround only because it is still imported by ipdb.",
     )
     )
 
 
 
 
-def BdbQuit_IPython_excepthook(self, et, ev, tb, tb_offset=None):
-    raise ValueError(
-        "`BdbQuit_IPython_excepthook` is deprecated since version 5.1",
-        DeprecationWarning, stacklevel=2)
-
-
 RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+')
 RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+')
 
 
 
 
@@ -191,6 +192,8 @@ class Pdb(OldPdb):
 
 
     """
     """
 
 
+    shell: InteractiveShell
+
     if CHAIN_EXCEPTIONS:
     if CHAIN_EXCEPTIONS:
         MAX_CHAINED_EXCEPTION_DEPTH = 999
         MAX_CHAINED_EXCEPTION_DEPTH = 999
 
 
@@ -261,21 +264,6 @@ class Pdb(OldPdb):
         C = coloransi.TermColors
         C = coloransi.TermColors
         cst = self.color_scheme_table
         cst = self.color_scheme_table
 
 
-        cst['NoColor'].colors.prompt = C.NoColor
-        cst['NoColor'].colors.breakpoint_enabled = C.NoColor
-        cst['NoColor'].colors.breakpoint_disabled = C.NoColor
-
-        cst['Linux'].colors.prompt = C.Green
-        cst['Linux'].colors.breakpoint_enabled = C.LightRed
-        cst['Linux'].colors.breakpoint_disabled = C.Red
-
-        cst['LightBG'].colors.prompt = C.Blue
-        cst['LightBG'].colors.breakpoint_enabled = C.LightRed
-        cst['LightBG'].colors.breakpoint_disabled = C.Red
-
-        cst['Neutral'].colors.prompt = C.Blue
-        cst['Neutral'].colors.breakpoint_enabled = C.LightRed
-        cst['Neutral'].colors.breakpoint_disabled = C.Red
 
 
         # Add a python parser so we can syntax highlight source while
         # Add a python parser so we can syntax highlight source while
         # debugging.
         # debugging.
@@ -471,24 +459,11 @@ class Pdb(OldPdb):
 
 
         return line
         return line
 
 
-    def new_do_frame(self, arg):
-        OldPdb.do_frame(self, arg)
-
     def new_do_quit(self, arg):
     def new_do_quit(self, arg):
-
-        if hasattr(self, 'old_all_completions'):
-            self.shell.Completer.all_completions = self.old_all_completions
-
         return OldPdb.do_quit(self, arg)
         return OldPdb.do_quit(self, arg)
 
 
     do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
     do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
 
 
-    def new_do_restart(self, arg):
-        """Restart command. In the context of ipython this is exactly the same
-        thing as 'quit'."""
-        self.msg("Restart doesn't make sense here. Using 'quit' instead.")
-        return self.do_quit(arg)
-
     def print_stack_trace(self, context=None):
     def print_stack_trace(self, context=None):
         Colors = self.color_scheme_table.active_colors
         Colors = self.color_scheme_table.active_colors
         ColorsNormal = Colors.Normal
         ColorsNormal = Colors.Normal
@@ -941,22 +916,37 @@ class Pdb(OldPdb):
         Utility to tell us whether we are in a decorator internal and should stop.
         Utility to tell us whether we are in a decorator internal and should stop.
 
 
         """
         """
-
         # if we are disabled don't skip
         # if we are disabled don't skip
         if not self._predicates["debuggerskip"]:
         if not self._predicates["debuggerskip"]:
             return False
             return False
 
 
+        return self._cachable_skip(frame)
+
+    @lru_cache(1024)
+    def _cached_one_parent_frame_debuggerskip(self, frame):
+        """
+        Cache looking up for DEBUGGERSKIP on parent frame.
+
+        This should speedup walking through deep frame when one of the highest
+        one does have a debugger skip.
+
+        This is likely to introduce fake positive though.
+        """
+        while getattr(frame, "f_back", None):
+            frame = frame.f_back
+            if self._get_frame_locals(frame).get(DEBUGGERSKIP):
+                return True
+        return None
+
+    @lru_cache(1024)
+    def _cachable_skip(self, frame):
         # if frame is tagged, skip by default.
         # if frame is tagged, skip by default.
         if DEBUGGERSKIP in frame.f_code.co_varnames:
         if DEBUGGERSKIP in frame.f_code.co_varnames:
             return True
             return True
 
 
         # if one of the parent frame value set to True skip as well.
         # if one of the parent frame value set to True skip as well.
-
-        cframe = frame
-        while getattr(cframe, "f_back", None):
-            cframe = cframe.f_back
-            if self._get_frame_locals(cframe).get(DEBUGGERSKIP):
-                return True
+        if self._cached_one_parent_frame_debuggerskip(frame):
+            return True
 
 
         return False
         return False
 
 

+ 1 - 1
contrib/python/ipython/py3/IPython/core/display_functions.py

@@ -111,7 +111,7 @@ def display(
     display_id=None,
     display_id=None,
     raw=False,
     raw=False,
     clear=False,
     clear=False,
-    **kwargs
+    **kwargs,
 ):
 ):
     """Display a Python object in all frontends.
     """Display a Python object in all frontends.
 
 

+ 20 - 3
contrib/python/ipython/py3/IPython/core/excolors.py

@@ -34,9 +34,10 @@ def exception_colors():
     >>> ec.active_scheme_name
     >>> ec.active_scheme_name
     'NoColor'
     'NoColor'
     >>> sorted(ec.active_colors.keys())
     >>> sorted(ec.active_colors.keys())
-    ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
-    'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
-    'val', 'valEm']
+    ['Normal', 'breakpoint_disabled', 'breakpoint_enabled', 'caret', 'em',
+    'excName', 'filename', 'filenameEm', 'line', 'lineno', 'linenoEm', 'name',
+    'nameEm', 'normalEm', 'prompt', 'topline', 'vName', 'val', 'valEm']
+
     """
     """
 
 
     ex_colors = ColorSchemeTable()
     ex_colors = ColorSchemeTable()
@@ -70,6 +71,10 @@ def exception_colors():
                 "line": C.NoColor,
                 "line": C.NoColor,
                 "caret": C.NoColor,
                 "caret": C.NoColor,
                 "Normal": C.NoColor,
                 "Normal": C.NoColor,
+                # debugger
+                "prompt": C.NoColor,
+                "breakpoint_enabled": C.NoColor,
+                "breakpoint_disabled": C.NoColor,
             },
             },
         )
         )
     )
     )
@@ -99,6 +104,10 @@ def exception_colors():
                 "line": C.Yellow,
                 "line": C.Yellow,
                 "caret": C.White,
                 "caret": C.White,
                 "Normal": C.Normal,
                 "Normal": C.Normal,
+                # debugger
+                "prompt": C.Green,
+                "breakpoint_enabled": C.LightRed,
+                "breakpoint_disabled": C.Red,
             },
             },
         )
         )
     )
     )
@@ -132,6 +141,10 @@ def exception_colors():
                 "line": C.Red,
                 "line": C.Red,
                 "caret": C.Normal,
                 "caret": C.Normal,
                 "Normal": C.Normal,
                 "Normal": C.Normal,
+                # debugger
+                "prompt": C.Blue,
+                "breakpoint_enabled": C.LightRed,
+                "breakpoint_disabled": C.Red,
             },
             },
         )
         )
     )
     )
@@ -161,6 +174,10 @@ def exception_colors():
                 "line": C.Red,
                 "line": C.Red,
                 "caret": C.Normal,
                 "caret": C.Normal,
                 "Normal": C.Normal,
                 "Normal": C.Normal,
+                # debugger
+                "prompt": C.Blue,
+                "breakpoint_enabled": C.LightRed,
+                "breakpoint_disabled": C.Red,
             },
             },
         )
         )
     )
     )

+ 8 - 1
contrib/python/ipython/py3/IPython/core/interactiveshell.py

@@ -3654,10 +3654,17 @@ class InteractiveShell(SingletonConfigurable):
             make sense in all contexts, for example a terminal ipython can't
             make sense in all contexts, for example a terminal ipython can't
             display figures inline.
             display figures inline.
         """
         """
+        from .pylabtools import _matplotlib_manages_backends
+
+        if not _matplotlib_manages_backends() and gui in (None, "auto"):
+            # Early import of backend_inline required for its side effect of
+            # calling _enable_matplotlib_integration()
+            import matplotlib_inline.backend_inline
+
         from IPython.core import pylabtools as pt
         from IPython.core import pylabtools as pt
         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
 
 
-        if gui != 'inline':
+        if gui != None:
             # If we have our first gui selection, store it
             # If we have our first gui selection, store it
             if self.pylab_gui_select is None:
             if self.pylab_gui_select is None:
                 self.pylab_gui_select = gui
                 self.pylab_gui_select = gui

+ 10 - 6
contrib/python/ipython/py3/IPython/core/magics/pylab.py

@@ -18,19 +18,19 @@ from IPython.core import magic_arguments
 from IPython.core.magic import Magics, magics_class, line_magic
 from IPython.core.magic import Magics, magics_class, line_magic
 from IPython.testing.skipdoctest import skip_doctest
 from IPython.testing.skipdoctest import skip_doctest
 from warnings import warn
 from warnings import warn
-from IPython.core.pylabtools import backends
 
 
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
 # Magic implementation classes
 # Magic implementation classes
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
 
 
 magic_gui_arg = magic_arguments.argument(
 magic_gui_arg = magic_arguments.argument(
-        'gui', nargs='?',
-        help="""Name of the matplotlib backend to use %s.
+    "gui",
+    nargs="?",
+    help="""Name of the matplotlib backend to use such as 'qt' or 'widget'.
         If given, the corresponding matplotlib backend is used,
         If given, the corresponding matplotlib backend is used,
         otherwise it will be matplotlib's default
         otherwise it will be matplotlib's default
         (which you can set in your matplotlib config file).
         (which you can set in your matplotlib config file).
-        """ % str(tuple(sorted(backends.keys())))
+        """,
 )
 )
 
 
 
 
@@ -93,8 +93,12 @@ class PylabMagics(Magics):
         """
         """
         args = magic_arguments.parse_argstring(self.matplotlib, line)
         args = magic_arguments.parse_argstring(self.matplotlib, line)
         if args.list:
         if args.list:
-            backends_list = list(backends.keys())
-            print("Available matplotlib backends: %s" % backends_list)
+            from IPython.core.pylabtools import _list_matplotlib_backends_and_gui_loops
+
+            print(
+                "Available matplotlib backends: %s"
+                % _list_matplotlib_backends_and_gui_loops()
+            )
         else:
         else:
             gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
             gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
             self._show_matplotlib_backend(args.gui, backend)
             self._show_matplotlib_backend(args.gui, backend)

+ 106 - 21
contrib/python/ipython/py3/IPython/core/pylabtools.py

@@ -12,9 +12,12 @@ import warnings
 from IPython.core.display import _pngxy
 from IPython.core.display import _pngxy
 from IPython.utils.decorators import flag_calls
 from IPython.utils.decorators import flag_calls
 
 
-# If user specifies a GUI, that dictates the backend, otherwise we read the
-# user's mpl default from the mpl rc structure
-backends = {
+
+# Matplotlib backend resolution functionality moved from IPython to Matplotlib
+# in IPython 8.24 and Matplotlib 3.9.1. Need to keep `backends` and `backend2gui`
+# here for earlier Matplotlib and for external backend libraries such as
+# mplcairo that might rely upon it.
+_deprecated_backends = {
     "tk": "TkAgg",
     "tk": "TkAgg",
     "gtk": "GTKAgg",
     "gtk": "GTKAgg",
     "gtk3": "GTK3Agg",
     "gtk3": "GTK3Agg",
@@ -41,29 +44,44 @@ backends = {
 # GUI support to activate based on the desired matplotlib backend.  For the
 # GUI support to activate based on the desired matplotlib backend.  For the
 # most part it's just a reverse of the above dict, but we also need to add a
 # most part it's just a reverse of the above dict, but we also need to add a
 # few others that map to the same GUI manually:
 # few others that map to the same GUI manually:
-backend2gui = dict(zip(backends.values(), backends.keys()))
+_deprecated_backend2gui = dict(
+    zip(_deprecated_backends.values(), _deprecated_backends.keys())
+)
 # In the reverse mapping, there are a few extra valid matplotlib backends that
 # In the reverse mapping, there are a few extra valid matplotlib backends that
 # map to the same GUI support
 # map to the same GUI support
-backend2gui["GTK"] = backend2gui["GTKCairo"] = "gtk"
-backend2gui["GTK3Cairo"] = "gtk3"
-backend2gui["GTK4Cairo"] = "gtk4"
-backend2gui["WX"] = "wx"
-backend2gui["CocoaAgg"] = "osx"
+_deprecated_backend2gui["GTK"] = _deprecated_backend2gui["GTKCairo"] = "gtk"
+_deprecated_backend2gui["GTK3Cairo"] = "gtk3"
+_deprecated_backend2gui["GTK4Cairo"] = "gtk4"
+_deprecated_backend2gui["WX"] = "wx"
+_deprecated_backend2gui["CocoaAgg"] = "osx"
 # There needs to be a hysteresis here as the new QtAgg Matplotlib backend
 # There needs to be a hysteresis here as the new QtAgg Matplotlib backend
 # supports either Qt5 or Qt6 and the IPython qt event loop support Qt4, Qt5,
 # supports either Qt5 or Qt6 and the IPython qt event loop support Qt4, Qt5,
 # and Qt6.
 # and Qt6.
-backend2gui["QtAgg"] = "qt"
-backend2gui["Qt4Agg"] = "qt4"
-backend2gui["Qt5Agg"] = "qt5"
+_deprecated_backend2gui["QtAgg"] = "qt"
+_deprecated_backend2gui["Qt4Agg"] = "qt4"
+_deprecated_backend2gui["Qt5Agg"] = "qt5"
 
 
 # And some backends that don't need GUI integration
 # And some backends that don't need GUI integration
-del backend2gui["nbAgg"]
-del backend2gui["agg"]
-del backend2gui["svg"]
-del backend2gui["pdf"]
-del backend2gui["ps"]
-del backend2gui["module://matplotlib_inline.backend_inline"]
-del backend2gui["module://ipympl.backend_nbagg"]
+del _deprecated_backend2gui["nbAgg"]
+del _deprecated_backend2gui["agg"]
+del _deprecated_backend2gui["svg"]
+del _deprecated_backend2gui["pdf"]
+del _deprecated_backend2gui["ps"]
+del _deprecated_backend2gui["module://matplotlib_inline.backend_inline"]
+del _deprecated_backend2gui["module://ipympl.backend_nbagg"]
+
+
+# Deprecated attributes backends and backend2gui mostly following PEP 562.
+def __getattr__(name):
+    if name in ("backends", "backend2gui"):
+        warnings.warn(
+            f"{name} is deprecated since IPython 8.24, backends are managed "
+            "in matplotlib and can be externally registered.",
+            DeprecationWarning,
+        )
+        return globals()[f"_deprecated_{name}"]
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
 
 
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
 # Matplotlib utilities
 # Matplotlib utilities
@@ -267,7 +285,7 @@ def select_figure_formats(shell, formats, **kwargs):
 
 
     [ f.pop(Figure, None) for f in shell.display_formatter.formatters.values() ]
     [ f.pop(Figure, None) for f in shell.display_formatter.formatters.values() ]
     mplbackend = matplotlib.get_backend().lower()
     mplbackend = matplotlib.get_backend().lower()
-    if mplbackend == 'nbagg' or mplbackend == 'module://ipympl.backend_nbagg':
+    if mplbackend in ("nbagg", "ipympl", "widget", "module://ipympl.backend_nbagg"):
         formatter = shell.display_formatter.ipython_display_formatter
         formatter = shell.display_formatter.ipython_display_formatter
         formatter.for_type(Figure, _reshow_nbagg_figure)
         formatter.for_type(Figure, _reshow_nbagg_figure)
 
 
@@ -319,7 +337,23 @@ def find_gui_and_backend(gui=None, gui_select=None):
 
 
     import matplotlib
     import matplotlib
 
 
-    has_unified_qt_backend = getattr(matplotlib, "__version_info__", (0, 0)) >= (3, 5)
+    if _matplotlib_manages_backends():
+        backend_registry = matplotlib.backends.registry.backend_registry
+
+        # gui argument may be a gui event loop or may be a backend name.
+        if gui in ("auto", None):
+            backend = matplotlib.rcParamsOrig["backend"]
+            backend, gui = backend_registry.resolve_backend(backend)
+        else:
+            backend, gui = backend_registry.resolve_gui_or_backend(gui)
+
+        return gui, backend
+
+    # Fallback to previous behaviour (Matplotlib < 3.9)
+    mpl_version_info = getattr(matplotlib, "__version_info__", (0, 0))
+    has_unified_qt_backend = mpl_version_info >= (3, 5)
+
+    from IPython.core.pylabtools import backends
 
 
     backends_ = dict(backends)
     backends_ = dict(backends)
     if not has_unified_qt_backend:
     if not has_unified_qt_backend:
@@ -338,6 +372,7 @@ def find_gui_and_backend(gui=None, gui_select=None):
         backend = matplotlib.rcParamsOrig['backend']
         backend = matplotlib.rcParamsOrig['backend']
         # In this case, we need to find what the appropriate gui selection call
         # In this case, we need to find what the appropriate gui selection call
         # should be for IPython, so we can activate inputhook accordingly
         # should be for IPython, so we can activate inputhook accordingly
+        from IPython.core.pylabtools import backend2gui
         gui = backend2gui.get(backend, None)
         gui = backend2gui.get(backend, None)
 
 
         # If we have already had a gui active, we need it and inline are the
         # If we have already had a gui active, we need it and inline are the
@@ -346,6 +381,11 @@ def find_gui_and_backend(gui=None, gui_select=None):
             gui = gui_select
             gui = gui_select
             backend = backends_[gui]
             backend = backends_[gui]
 
 
+    # Matplotlib before _matplotlib_manages_backends() can return "inline" for
+    # no gui event loop rather than the None that IPython >= 8.24.0 expects.
+    if gui == "inline":
+        gui = None
+
     return gui, backend
     return gui, backend
 
 
 
 
@@ -431,3 +471,48 @@ def configure_inline_support(shell, backend):
     )
     )
 
 
     configure_inline_support_orig(shell, backend)
     configure_inline_support_orig(shell, backend)
+
+
+# Determine if Matplotlib manages backends only if needed, and cache result.
+# Do not read this directly, instead use _matplotlib_manages_backends().
+_matplotlib_manages_backends_value: bool | None = None
+
+
+def _matplotlib_manages_backends() -> bool:
+    """Return True if Matplotlib manages backends, False otherwise.
+
+    If it returns True, the caller can be sure that
+    matplotlib.backends.registry.backend_registry is available along with
+    member functions resolve_gui_or_backend, resolve_backend, list_all, and
+    list_gui_frameworks.
+    """
+    global _matplotlib_manages_backends_value
+    if _matplotlib_manages_backends_value is None:
+        try:
+            from matplotlib.backends.registry import backend_registry
+
+            _matplotlib_manages_backends_value = hasattr(
+                backend_registry, "resolve_gui_or_backend"
+            )
+        except ImportError:
+            _matplotlib_manages_backends_value = False
+
+    return _matplotlib_manages_backends_value
+
+
+def _list_matplotlib_backends_and_gui_loops() -> list[str]:
+    """Return list of all Matplotlib backends and GUI event loops.
+
+    This is the list returned by
+        %matplotlib --list
+    """
+    if _matplotlib_manages_backends():
+        from matplotlib.backends.registry import backend_registry
+
+        ret = backend_registry.list_all() + backend_registry.list_gui_frameworks()
+    else:
+        from IPython.core import pylabtools
+
+        ret = list(pylabtools.backends.keys())
+
+    return sorted(["auto"] + ret)

+ 1 - 1
contrib/python/ipython/py3/IPython/core/release.py

@@ -16,7 +16,7 @@
 # release.  'dev' as a _version_extra string means this is a development
 # release.  'dev' as a _version_extra string means this is a development
 # version
 # version
 _version_major = 8
 _version_major = 8
-_version_minor = 23
+_version_minor = 24
 _version_patch = 0
 _version_patch = 0
 _version_extra = ".dev"
 _version_extra = ".dev"
 # _version_extra = "rc1"
 # _version_extra = "rc1"

+ 65 - 25
contrib/python/ipython/py3/IPython/core/shellapp.py

@@ -11,37 +11,45 @@ import glob
 from itertools import chain
 from itertools import chain
 import os
 import os
 import sys
 import sys
+import typing as t
 
 
 from traitlets.config.application import boolean_flag
 from traitlets.config.application import boolean_flag
 from traitlets.config.configurable import Configurable
 from traitlets.config.configurable import Configurable
 from traitlets.config.loader import Config
 from traitlets.config.loader import Config
 from IPython.core.application import SYSTEM_CONFIG_DIRS, ENV_CONFIG_DIRS
 from IPython.core.application import SYSTEM_CONFIG_DIRS, ENV_CONFIG_DIRS
-from IPython.core import pylabtools
 from IPython.utils.contexts import preserve_keys
 from IPython.utils.contexts import preserve_keys
 from IPython.utils.path import filefind
 from IPython.utils.path import filefind
 from traitlets import (
 from traitlets import (
-    Unicode, Instance, List, Bool, CaselessStrEnum, observe,
+    Unicode,
+    Instance,
+    List,
+    Bool,
+    CaselessStrEnum,
+    observe,
     DottedObjectName,
     DottedObjectName,
+    Undefined,
 )
 )
 from IPython.terminal import pt_inputhooks
 from IPython.terminal import pt_inputhooks
 
 
-#-----------------------------------------------------------------------------
+# -----------------------------------------------------------------------------
 # Aliases and Flags
 # Aliases and Flags
-#-----------------------------------------------------------------------------
+# -----------------------------------------------------------------------------
 
 
 gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases))
 gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases))
 
 
-backend_keys = sorted(pylabtools.backends.keys())
-backend_keys.insert(0, 'auto')
-
 shell_flags = {}
 shell_flags = {}
 
 
 addflag = lambda *args: shell_flags.update(boolean_flag(*args))
 addflag = lambda *args: shell_flags.update(boolean_flag(*args))
-addflag('autoindent', 'InteractiveShell.autoindent',
-        'Turn on autoindenting.', 'Turn off autoindenting.'
+addflag(
+    "autoindent",
+    "InteractiveShell.autoindent",
+    "Turn on autoindenting.",
+    "Turn off autoindenting.",
 )
 )
-addflag('automagic', 'InteractiveShell.automagic',
-        """Turn on the auto calling of magic commands. Type %%magic at the
+addflag(
+    "automagic",
+    "InteractiveShell.automagic",
+    """Turn on the auto calling of magic commands. Type %%magic at the
         IPython  prompt  for  more information.""",
         IPython  prompt  for  more information.""",
         'Turn off the auto calling of magic commands.'
         'Turn off the auto calling of magic commands.'
 )
 )
@@ -97,6 +105,37 @@ shell_aliases = dict(
 )
 )
 shell_aliases['cache-size'] = 'InteractiveShell.cache_size'
 shell_aliases['cache-size'] = 'InteractiveShell.cache_size'
 
 
+
+# -----------------------------------------------------------------------------
+# Traitlets
+# -----------------------------------------------------------------------------
+
+
+class MatplotlibBackendCaselessStrEnum(CaselessStrEnum):
+    """An enum of Matplotlib backend strings where the case should be ignored.
+
+    Prior to Matplotlib 3.9.1 the list of valid backends is hardcoded in
+    pylabtools.backends. After that, Matplotlib manages backends.
+
+    The list of valid backends is determined when it is first needed to avoid
+    wasting unnecessary initialisation time.
+    """
+
+    def __init__(
+        self: CaselessStrEnum[t.Any],
+        default_value: t.Any = Undefined,
+        **kwargs: t.Any,
+    ) -> None:
+        super().__init__(None, default_value=default_value, **kwargs)
+
+    def __getattribute__(self, name):
+        if name == "values" and object.__getattribute__(self, name) is None:
+            from IPython.core.pylabtools import _list_matplotlib_backends_and_gui_loops
+
+            self.values = _list_matplotlib_backends_and_gui_loops()
+        return object.__getattribute__(self, name)
+
+
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
 # Main classes and functions
 # Main classes and functions
 #-----------------------------------------------------------------------------
 #-----------------------------------------------------------------------------
@@ -156,30 +195,31 @@ class InteractiveShellApp(Configurable):
     exec_lines = List(Unicode(),
     exec_lines = List(Unicode(),
         help="""lines of code to run at IPython startup."""
         help="""lines of code to run at IPython startup."""
     ).tag(config=True)
     ).tag(config=True)
-    code_to_run = Unicode('',
-        help="Execute the given command string."
-    ).tag(config=True)
-    module_to_run = Unicode('',
-        help="Run the module as a script."
+    code_to_run = Unicode("", help="Execute the given command string.").tag(config=True)
+    module_to_run = Unicode("", help="Run the module as a script.").tag(config=True)
+    gui = CaselessStrEnum(
+        gui_keys,
+        allow_none=True,
+        help="Enable GUI event loop integration with any of {0}.".format(gui_keys),
     ).tag(config=True)
     ).tag(config=True)
-    gui = CaselessStrEnum(gui_keys, allow_none=True,
-        help="Enable GUI event loop integration with any of {0}.".format(gui_keys)
-    ).tag(config=True)
-    matplotlib = CaselessStrEnum(backend_keys, allow_none=True,
+    matplotlib = MatplotlibBackendCaselessStrEnum(
+        allow_none=True,
         help="""Configure matplotlib for interactive use with
         help="""Configure matplotlib for interactive use with
-        the default matplotlib backend."""
+        the default matplotlib backend.""",
     ).tag(config=True)
     ).tag(config=True)
-    pylab = CaselessStrEnum(backend_keys, allow_none=True,
+    pylab = MatplotlibBackendCaselessStrEnum(
+        allow_none=True,
         help="""Pre-load matplotlib and numpy for interactive use,
         help="""Pre-load matplotlib and numpy for interactive use,
         selecting a particular matplotlib backend and loop integration.
         selecting a particular matplotlib backend and loop integration.
-        """
+        """,
     ).tag(config=True)
     ).tag(config=True)
-    pylab_import_all = Bool(True,
+    pylab_import_all = Bool(
+        True,
         help="""If true, IPython will populate the user namespace with numpy, pylab, etc.
         help="""If true, IPython will populate the user namespace with numpy, pylab, etc.
         and an ``import *`` is done from numpy and pylab, when using pylab mode.
         and an ``import *`` is done from numpy and pylab, when using pylab mode.
 
 
         When False, pylab mode should not import any names into the user namespace.
         When False, pylab mode should not import any names into the user namespace.
-        """
+        """,
     ).tag(config=True)
     ).tag(config=True)
     ignore_cwd = Bool(
     ignore_cwd = Bool(
         False,
         False,

+ 1 - 1
contrib/python/ipython/py3/IPython/terminal/embed.py

@@ -197,7 +197,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
         dummy=None,
         dummy=None,
         stack_depth=1,
         stack_depth=1,
         compile_flags=None,
         compile_flags=None,
-        **kw
+        **kw,
     ):
     ):
         """Activate the interactive interpreter.
         """Activate the interactive interpreter.
 
 

Некоторые файлы не были показаны из-за большого количества измененных файлов