8000 MNT: use a property rather than assignment to manage alias · matplotlib/matplotlib@cef64ad · GitHub
[go: up one dir, main page]

Skip to content

Commit cef64ad

Browse files
committed
MNT: use a property rather than assignment to manage alias
1 parent cff76d1 commit cef64ad

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/matplotlib/figure.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,13 +949,16 @@ def clear(self, keep_observers=False):
949949

950950
self.stale = True
951951

952-
# synonym for `clear`.
953-
clf = clear
952+
# synonym for `clear`. We do this with a property to make sure that we get
953+
# a literal alias that correctly behaves for sub-classes (without resorting
954+
# to __subclass_init__ or other meta-programming tools.
955+
@property
956+
def clf(self):
957+
return self.clear
954958

955959
# Note: in the docstring below, the newlines in the examples after the
956960
# calls to legend() allow replacing it with figlegend() to generate the
957961
# docstring of pyplot.figlegend.
958-
959962
@_docstring.dedent_interpd
960963
def legend(self, *args, **kwargs):
961964
"""
@@ -2848,9 +2851,6 @@ def clear(self, keep_observers=False):
28482851
if toolbar is not None:
28492852
toolbar.update()
28502853

2851-
# synonym for `clear`.
2852-
clf = clear
2853-
28542854
@_finalize_rasterization
28552855
@allow_rasterization
28562856
def draw(self, renderer):

lib/matplotlib/tests/test_figure.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,12 @@ def test_figure_clear():
791791

792792

793793
def test_clf_is_clear():
794-
for cls in [FigureBase] + FigureBase.__subclasses__():
795-
assert cls.clf is cls.clear
796-
assert cls.clear.__name__ == 'clear'
794+
fig = Figure()
795+
subfig = fig.subfigures()
797796

797+
for f in [fig, subfig]:
798+
assert f.clear.__func__ is f.clf.__func__
799+
assert f.clear.__func__.__name__ == 'clear'
798800

799801
@mpl.style.context('mpl20')
800802
def test_picking_does_not_stale():

0 commit comments

Comments
 (0)
0