diff --git a/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py b/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py index ef185b798..d10f85b37 100644 --- a/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py +++ b/src/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py @@ -53,10 +53,30 @@ def find_gui_and_backend(): return gui, backend +def _get_major_version(module): + return int(module.__version__.split('.')[0]) + + +def _get_minor_version(module): + return int(module.__version__.split('.')[1]) + + def is_interactive_backend(backend): """Check if backend is interactive""" matplotlib = sys.modules["matplotlib"] - from matplotlib.rcsetup import interactive_bk, non_interactive_bk # @UnresolvedImport + new_api_version = (3, 9) + installed_version = ( + _get_major_version(matplotlib), + _get_minor_version(matplotlib) + ) + + if installed_version >= new_api_version: + interactive_bk = matplotlib.backends.backend_registry.list_builtin( + matplotlib.backends.BackendFilter.INTERACTIVE) + non_interactive_bk = matplotlib.backends.backend_registry.list_builtin( + matplotlib.backends.BackendFilter.NON_INTERACTIVE) + else: + from matplotlib.rcsetup import interactive_bk, non_interactive_bk # @UnresolvedImport if backend in interactive_bk: return True