From e2c96a999d527d21b717281b5c4e86afef255c12 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 24 Aug 2023 23:19:17 +0200 Subject: [PATCH] Backport PR #26591: Fix ToolBase.figure property setter. --- lib/matplotlib/backend_tools.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index 4df80ef5bda6..ac2a20f1ffa9 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -118,16 +118,15 @@ def __init__(self, toolmanager, name): lambda self: self._figure.canvas if self._figure is not None else None, doc="The canvas of the figure affected by this tool, or None.") - @property - def figure(self): - """The Figure affected by this tool, or None.""" - return self._figure - - @figure.setter - def figure(self, figure): + def set_figure(self, figure): self._figure = figure - set_figure = figure.fset + figure = property( + lambda self: self._figure, + # The setter must explicitly call self.set_figure so that subclasses can + # meaningfully override it. + lambda self, figure: self.set_figure(figure), + doc="The Figure affected by this tool, or None.") def _make_classic_style_pseudo_toolbar(self): """
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: