Skip to content

Commit 3981bb3

Browse files
committed
Fix ToolBase.figure property setter.
The property must be defined to use self.set_figure as the setter, and not the other way round; otherwise, subclasses that override set_figure (such as ToolToggleBase) won't override the setter on the property.
1 parent a4dca24 commit 3981bb3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/matplotlib/backend_tools.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,15 @@ def __init__(self, toolmanager, name):
118118
lambda self: self._figure.canvas if self._figure is not None else None,
119119
doc="The canvas of the figure affected by this tool, or None.")
120120

121-
@property
122-
def figure(self):
123-
"""The Figure affected by this tool, or None."""
124-
return self._figure
125-
126-
@figure.setter
127-
def figure(self, figure):
121+
def set_figure(self, figure):
128122
self._figure = figure
129123

130-
set_figure = figure.fset
124+
figure = property(
125+
lambda self: self._figure,
126+
# The setter must explicitly call self.set_figure so that subclasses can
127+
# meaningfully override it.
128+
lambda self, figure: self.set_figure(figure),
129+
doc="The Figure affected by this tool, or None.")
131130

132131
def _make_classic_style_pseudo_toolbar(self):
133132
"""

0 commit comments

Comments
 (0)