Issue 1:
Bug summary

matplotlib.get_backend() fails with the indicated exception. This method is also executed when the debugger hits a breakpoint, even if not actually using matplotlib. A fix/workaround is included.

Code for reproduction

import unittest
class Test(unittest.TestCase):
def test(self): # Debug this test.
pass # Place a breakpoint here.

# Alternatively, without a unit test:
import matplotlib
print(matplotlib.get_backend())

Actual outcome

./tests/test_test.py::Test::test Failed with Error: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'
File "C:\Program Files\Python310\lib\unittest\case.py", line 59, in testPartExecutor
yield
File "C:\Program Files\Python310\lib\unittest\case.py", line 591, in run
self._callTestMethod(testMethod)
File "C:\Program Files\Python310\lib\unittest\case.py", line 549, in _callTestMethod
method()
File "D:\Lasertrimmer\Software\ltsoftware\tests\test_test.py", line 4, in test
pass
File "D:\Lasertrimmer\Software\ltsoftware\tests\test_test.py", line 4, in test
pass
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 987, in trace_dispatch
self.do_wait_suspend(thread, frame, event, arg)
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 164, in do_wait_suspend
self._args[0].do_wait_suspend(*args, **kwargs)
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 2062, in do_wait_suspend
keep_suspended = self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 2085, in _do_wait_suspend
self._activate_gui_if_needed()
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 1581, in _activate_gui_if_needed
activate_function()
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydevd.py", line 1565, in <lambda>
self.mpl_modules_for_patching = {"matplotlib": lambda: activate_matplotlib(do_enable_gui),
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\matplotlibtools.py", line 93, in activate_matplotlib
gui, backend = find_gui_and_backend()
File "c:\Users\laboreng\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\matplotlibtools.py", line 45, in find_gui_and_backend
backend = matplotlib.rcParams['backend']
File "C:\Users\laboreng\AppData\Roaming\Python\Python310\site-packages\matplotlib\__init__.py", line 677, in __getitem__
plt.switch_backend(rcsetup._auto_backend_sentinel)
File "C:\Users\laboreng\AppData\Roaming\Python\Python310\site-packages\matplotlib\pyplot.py", line 252, in switch_backend
switch_backend(candidate)
File "C:\Users\laboreng\AppData\Roaming\Python\Python310\site-packages\matplotlib\pyplot.py", line 265, in switch_backend
backend_mod = importlib.import_module(
File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\laboreng\AppData\Roaming\Python\Python310\site-packages\matplotlib\backends\backend_qtagg.py", line 12, in <module>
from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
File "C:\Users\laboreng\AppData\Roaming\Python\Python310\site-packages\matplotlib\backends\backend_qt.py", line 72, in <module>
_MODIFIER_KEYS = [
File "C:\Users\laboreng\AppData\Roaming\Python\Python310\site-packages\matplotlib\backends\backend_qt.py", line 73, in <listcomp>
(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'KeyboardModifier'

Expected outcome

VSCode should stay at the breakpoint without raising an exception. The alternative code should print QtAgg without raising an exception.

Additional information

Just running (not debugging) the code does not cause the problem.

Debugging the code when no breakpoint is hit does not cause the problem.

matplotlib.get_backend() is called automatically when the debugger hits a breakpoint (even when not actually using matplotlib in the code), which causes the exception.

The issue is probably not triggered if

explicitly using another backend than PySide6

PyQt6 is installed as well

On my system, I was able to fix the behaviour as follows:

--- "a/C:\\Users\\laboreng\\AppData\\Roaming\\Python\\Python310\\site-packages\\matplotlib\\backends\\qt_compat.py"
+++ "b/C:\\Users\\laboreng\\AppData\\Roaming\\Python\\Python310\\site-packages\\matplotlib\\backends\\qt_compat_fix.py"
@@ -141,7 +141,7 @@ if (sys.platform == 'darwin' and
# PyQt6 enum compat helpers.

-_to_int = operator.attrgetter("value") if QT_API == "PyQt6" else int
+_to_int = operator.attrgetter("value") if QT_API in ["PyQt6", "PySide6"] else int

@functools.lru_cache(None)

Operating system

Windows 11

Matplotlib Version

3.6.1

Matplotlib Backend

QtAgg (code fails without the indicated fix)

Python version

Python 3.10.8

Jupyter version

No response

Installation

pip

Issue 2:
Bug summary

Error while importing matplotlib qt backend.

The version details are as below

matplotlib: 3.6.1

pyside: 6.4.0

python: 3.9.9

on a macOS-M1 machine.

Code for reproduction

from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar

Actual outcome

Traceback (most recent call last):

File "", line 1, in

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py", line 12, in

from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 72, in

_MODIFIER_KEYS = [

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_qt.py", line 73, in

(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),

TypeError: int() argument must be a string, a bytes-like object or a number, not 'KeyboardModifier'

Expected outcome

No error!

Additional information

No response

Operating system

OS/X

Matplotlib Version

3.6.1

Matplotlib Backend

MacOSX

Python version

3.9.9

Jupyter version

No response

Installation

pip