8000 FIX: if we have already subclassed mixin class just return · matplotlib/matplotlib@c39207d · GitHub
[go: up one dir, main page]

Skip to content

Commit c39207d

Browse files
committed
FIX: if we have already subclassed mixin class just return
If subplot_class_factory is passed a base class that already sub-classes the mixin class, simply return the base class. This will allow third-party packages to derive from maxes.Subplot rather than maxes.Axes which will allow easier (by ensuring that our classes and the third-party classes do not mix in the mro).
1 parent f4c518e commit c39207d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,10 @@ def _make_class_factory(mixin_class, fmt, attr_name=None):
22112211

22122212
@functools.lru_cache(None)
22132213
def class_factory(axes_class):
2214+
# if we have already wrapped this class, declare victory!
2215+
if issubclass(axes_class, mixin_class):
2216+
return axes_class
2217+
22142218
# The parameter is named "axes_class" for backcompat but is really just
22152219
# a base class; no axes semantics are used.
22162220
base_class = axes_class

lib/matplotlib/tests/test_subplots.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import matplotlib.pyplot as plt
77
from matplotlib.testing.decorators import image_comparison
8+
import matplotlib.axes as maxes
89

910

1011
def check_shared(axs, x_shared, y_shared):
@@ -219,3 +220,8 @@ def test_dont_mutate_kwargs():
219220
gridspec_kw=gridspec_kw)
220221
assert subplot_kw == {'sharex': 'all'}
221222
assert gridspec_kw == {'width_ratios': [1, 2]}
223+
224+
225+
def test_subplot_factory_reapplication():
226+
assert maxes.subplot_class_factory(maxes.Axes) is maxes.Subplot
227+
assert maxes.subplot_class_factory(maxes.Subplot) is maxes.Subplot

0 commit comments

Comments
 (0)
0