Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63e7554

Browse files
authored
Merge pull request #18354 from meeseeksmachine/auto-backport-of-pr-18352-on-v3.3.x
Backport PR #18352 on branch v3.3.x (Avoid triggering backend resolution during qt initial import.)
2 parents d79332d + 7466fe5 commit 63e7554

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
QT_API = QT_API_PYSIDE
4343
# Otherwise, check the QT_API environment variable (from Enthought). This can
4444
# only override the binding, not the backend (in other words, we check that the
45-
# requested backend actually matches).
46-
elif mpl.rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
45+
# requested backend actually matches). Use dict.__getitem__ to avoid
46+
# triggering backend resolution (which can result in a partially but
47+
# incompletely imported backend_qt5).
48+
elif dict.__getitem__(mpl.rcParams, "backend") in ["Qt5Agg", "Qt5Cairo"]:
4749
if QT_API_ENV in ["pyqt5", "pyside2"]:
4850
QT_API = _ETS[QT_API_ENV]
4951
else:
5052
QT_API = None
51-
elif mpl.rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
53+
elif dict.__getitem__(mpl.rcParams, "backend") in ["Qt4Agg", "Qt4Cairo"]:
5254
if QT_API_ENV in ["pyqt4", "pyside"]:
5355
QT_API = _ETS[QT_API_ENV]
5456
else:
@@ -150,8 +152,8 @@ def is_pyqt5():
150152
_setup_pyqt5()
151153
elif QT_API in [QT_API_PYQTv2, QT_API_PYSIDE, QT_API_PYQT]:
152154
_setup_pyqt4()
153-
elif QT_API is None:
154-
if mpl.rcParams["backend"] == "Qt4Agg":
155+
elif QT_API is None: # See above re: dict.__getitem__.
156+
if dict.__getitem__(mpl.rcParams, "backend") == "Qt4Agg":
155157
_candidates = [(_setup_pyqt4, QT_API_PYQTv2),
156158
(_setup_pyqt4, QT_API_PYSIDE),
157159
(_setup_pyqt4, QT_API_PYQT),

0 commit comments

Comments
 (0)