|  | 
| 1 |  | -import functools | 
| 2 |  | - | 
| 3 |  | -from matplotlib import _api | 
|  | 1 | +from matplotlib import _api, cbook | 
| 4 | 2 | from matplotlib.axes._axes import Axes | 
| 5 | 3 | from matplotlib.gridspec import GridSpec, SubplotSpec | 
| 6 | 4 | 
 | 
| @@ -36,15 +34,6 @@ def __init__(self, fig, *args, **kwargs): | 
| 36 | 34 |         # This will also update the axes position. | 
| 37 | 35 |         self.set_subplotspec(SubplotSpec._from_subplot_args(fig, args)) | 
| 38 | 36 | 
 | 
| 39 |  | -    def __reduce__(self): | 
| 40 |  | -        # get the first axes class which does not inherit from a subplotbase | 
| 41 |  | -        axes_class = next( | 
| 42 |  | -            c for c in type(self).__mro__ | 
| 43 |  | -            if issubclass(c, Axes) and not issubclass(c, SubplotBase)) | 
| 44 |  | -        return (_picklable_subplot_class_constructor, | 
| 45 |  | -                (axes_class,), | 
| 46 |  | -                self.__getstate__()) | 
| 47 |  | - | 
| 48 | 37 |     @_api.deprecated( | 
| 49 | 38 |         "3.4", alternative="get_subplotspec", | 
| 50 | 39 |         addendum="(get_subplotspec returns a SubplotSpec instance.)") | 
| @@ -169,53 +158,6 @@ def _make_twin_axes(self, *args, **kwargs): | 
| 169 | 158 |         return twin | 
| 170 | 159 | 
 | 
| 171 | 160 | 
 | 
| 172 |  | -# this here to support cartopy which was using a private part of the | 
| 173 |  | -# API to register their Axes subclasses. | 
| 174 |  | - | 
| 175 |  | -# In 3.1 this should be changed to a dict subclass that warns on use | 
| 176 |  | -# In 3.3 to a dict subclass that raises a useful exception on use | 
| 177 |  | -# In 3.4 should be removed | 
| 178 |  | - | 
| 179 |  | -# The slow timeline is to give cartopy enough time to get several | 
| 180 |  | -# release out before we break them. | 
| 181 |  | -_subplot_classes = {} | 
| 182 |  | - | 
| 183 |  | - | 
| 184 |  | -@functools.lru_cache(None) | 
| 185 |  | -def subplot_class_factory(axes_class=None): | 
| 186 |  | -    """ | 
| 187 |  | -    Make a new class that inherits from `.SubplotBase` and the | 
| 188 |  | -    given axes_class (which is assumed to be a subclass of `.axes.Axes`). | 
| 189 |  | -    This is perhaps a little bit roundabout to make a new class on | 
| 190 |  | -    the fly like this, but it means that a new Subplot class does | 
| 191 |  | -    not have to be created for every type of Axes. | 
| 192 |  | -    """ | 
| 193 |  | -    if axes_class is None: | 
| 194 |  | -        _api.warn_deprecated( | 
| 195 |  | -            "3.3", message="Support for passing None to subplot_class_factory " | 
| 196 |  | -            "is deprecated since %(since)s; explicitly pass the default Axes " | 
| 197 |  | -            "class instead. This will become an error %(removal)s.") | 
| 198 |  | -        axes_class = Axes | 
| 199 |  | -    try: | 
| 200 |  | -        # Avoid creating two different instances of GeoAxesSubplot... | 
| 201 |  | -        # Only a temporary backcompat fix.  This should be removed in | 
| 202 |  | -        # 3.4 | 
| 203 |  | -        return next(cls for cls in SubplotBase.__subclasses__() | 
| 204 |  | -                    if cls.__bases__ == (SubplotBase, axes_class)) | 
| 205 |  | -    except StopIteration: | 
| 206 |  | -        return type("%sSubplot" % axes_class.__name__, | 
| 207 |  | -                    (SubplotBase, axes_class), | 
| 208 |  | -                    {'_axes_class': axes_class}) | 
| 209 |  | - | 
| 210 |  | - | 
|  | 161 | +subplot_class_factory = cbook._make_class_factory( | 
|  | 162 | +    SubplotBase, "{}Subplot", "_axes_class") | 
| 211 | 163 | Subplot = subplot_class_factory(Axes)  # Provided for backward compatibility. | 
| 212 |  | - | 
| 213 |  | - | 
| 214 |  | -def _picklable_subplot_class_constructor(axes_class): | 
| 215 |  | -    """ | 
| 216 |  | -    Stub factory that returns an empty instance of the appropriate subplot | 
| 217 |  | -    class when called with an axes class. This is purely to allow pickling of | 
| 218 |  | -    Axes and Subplots. | 
| 219 |  | -    """ | 
| 220 |  | -    subplot_class = subplot_class_factory(axes_class) | 
| 221 |  | -    return subplot_class.__new__(subplot_class) | 
0 commit comments