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

Skip to content

Commit e4e4709

Browse files
authored
Merge pull request #25246 from meeseeksmachine/auto-backport-of-pr-25240-on-v3.7.x
Backport PR #25240 on branch v3.7.x (Avoid calling vars() on arbitrary third-party manager_class.)
2 parents a660f2d + f90a885 commit e4e4709

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
@@ -325,11 +325,12 @@ def draw_if_interactive():
325325
# show is already present, as the latter may be here for backcompat.
326326
manager_class = getattr(getattr(backend_mod, "FigureCanvas", None),
327327
"manager_class", None)
328-
# We can't compare directly manager_class.pyplot_show and FMB.pyplot_show
329-
# because pyplot_show is a classmethod so the above constructs are bound
330-
# classmethods, & thus always different (being bound to different classes).
331-
manager_pyplot_show = vars(manager_class).get("pyplot_show")
332-
base_pyplot_show = vars(FigureManagerBase).get("pyplot_show")
328+
# We can't compare directly manager_class.pyplot_show and FMB.pyplot_show because
329+
# pyplot_show is a classmethod so the above constructs are bound classmethods, and
330+
# thus always different (being bound to different classes). We also have to use
331+
# getattr_static instead of vars as manager_class could have no __dict__.
332+
manager_pyplot_show = inspect.getattr_static(manager_class, "pyplot_show", None)
333+
base_pyplot_show = inspect.getattr_static(FigureManagerBase, "pyplot_show", None)
333334
if (show is None
334335
or (manager_pyplot_show is not None
335336
and manager_pyplot_show != base_pyplot_show)):

0 commit comments

Comments
 (0)