Skip to content

Commit 2b05ace

Browse files
authored
Merge pull request #25240 from anntzer/uv
Avoid calling vars() on arbitrary third-party manager_class.
2 parents 60f0175 + 023f3c5 commit 2b05ace

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def _tight_layout(self):
898898
self._figure.tight_layout()
899899
for attr, spinbox in self._spinboxes.items():
900900
spinbox.blockSignals(True)
901-
spinbox.setValue(vars(self._figure.subplotpars)[attr])
901+
spinbox.setValue(getattr(self._figure.subplotpars, attr))
902902
spinbox.blockSignals(False)
903903
self._figure.canvas.draw_idle()
904904

lib/matplotlib/pyplot.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ def draw_if_interactive():
324324
# show is already present, as the latter may be here for backcompat.
325325
manager_class = getattr(getattr(backend_mod, "FigureCanvas", None),
326326
"manager_class", None)
327-
# We can't compare directly manager_class.pyplot_show and FMB.pyplot_show
328-
# because pyplot_show is a classmethod so the above constructs are bound
329-
# classmethods, & thus always different (being bound to different classes).
330-
manager_pyplot_show = vars(manager_class).get("pyplot_show")
331-
base_pyplot_show = vars(FigureManagerBase).get("pyplot_show")
327+
# We can't compare directly manager_class.pyplot_show and FMB.pyplot_show because
328+
# pyplot_show is a classmethod so the above constructs are bound classmethods, and
329+
# thus always different (being bound to different classes). We also have to use
330+
# getattr_static instead of vars as manager_class could have no __dict__.
331+
manager_pyplot_show = inspect.getattr_static(manager_class, "pyplot_show", None)
332+
base_pyplot_show = inspect.getattr_static(FigureManagerBase, "pyplot_show", None)
332333
if (show is None
333334
or (manager_pyplot_show is not None
334335
and manager_pyplot_show != base_pyplot_show)):

0 commit comments

Comments
 (0)