Skip to content

Expire BoxStyle._Base deprecation. #23237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/removals/23237-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``BoxStyle._Base`` and ``transmute`` method of boxstyles
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... have been removed. Boxstyles implemented as classes no longer need to
inherit from a base class.
106 changes: 14 additions & 92 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,94 +2268,18 @@ class BoxStyle(_Style):

%(AvailableBoxstyles)s

An instance of any boxstyle class is an callable object,
whose call signature is::
An instance of a boxstyle class is a callable object, with the signature ::

__call__(self, x0, y0, width, height, mutation_size)
__call__(self, x0, y0, width, height, mutation_size) -> Path

and returns a `.Path` instance. *x0*, *y0*, *width* and
*height* specify the location and size of the box to be
drawn. *mutation_scale* determines the overall size of the
mutation (by which I mean the transformation of the rectangle to
the fancy box).
*x0*, *y0*, *width* and *height* specify the location and size of the box
to be drawn; *mutation_size* scales the outline properties such as padding.
"""

_style_list = {}

@_api.deprecated("3.4")
class _Base:
"""
Abstract base class for styling of `.FancyBboxPatch`.

This class is not an artist itself. The `__call__` method returns the
`~matplotlib.path.Path` for outlining the fancy box. The actual drawing
is handled in `.FancyBboxPatch`.

Subclasses may only use parameters with default values in their
``__init__`` method because they must be able to be initialized
without arguments.

Subclasses must implement the `__call__` method. It receives the
enclosing rectangle *x0, y0, width, height* as well as the
*mutation_size*, which scales the outline properties such as padding.
It returns the outline of the fancy box as `.path.Path`.
"""

@_api.deprecated("3.4")
def transmute(self, x0, y0, width, height, mutation_size):
"""Return the `~.path.Path` outlining the given rectangle."""
return self(self, x0, y0, width, height, mutation_size, 1)

# This can go away once the deprecation period elapses, leaving _Base
# as a fully abstract base class just providing docstrings, no logic.
def __init_subclass__(cls):
transmute = _api.deprecate_method_override(
__class__.transmute, cls, since="3.4")
if transmute:
cls.__call__ = transmute
return

__call__ = cls.__call__

@_api.delete_parameter("3.4", "mutation_aspect")
def call_wrapper(
self, x0, y0, width, height, mutation_size,
mutation_aspect=_api.deprecation._deprecated_parameter):
if mutation_aspect is _api.deprecation._deprecated_parameter:
# Don't trigger deprecation warning internally.
return __call__(self, x0, y0, width, height, mutation_size)
else:
# Squeeze the given height by the aspect_ratio.
y0, height = y0 / mutation_aspect, height / mutation_aspect
path = self(x0, y0, width, height, mutation_size,
mutation_aspect)
vertices, codes = path.vertices, path.codes
# Restore the height.
vertices[:, 1] = vertices[:, 1] * mutation_aspect
return Path(vertices, codes)

cls.__call__ = call_wrapper

def __call__(self, x0, y0, width, height, mutation_size):
"""
Given the location and size of the box, return the path of
the box around it.

Parameters
----------
x0, y0, width, height : float
Location and size of the box.
mutation_size : float
A reference scale for the mutation.

Returns
-------
`~matplotlib.path.Path`
"""
raise NotImplementedError('Derived must override')

@_register_style(_style_list)
class Square(_Base):
class Square:
"""A square box."""

def __init__(self, pad=0.3):
Expand All @@ -2378,7 +2302,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
closed=True)

@_register_style(_style_list)
class Circle(_Base):
class Circle:
"""A circular box."""

def __init__(self, pad=0.3):
Expand All @@ -2399,7 +2323,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
max(width, height) / 2)

@_register_style(_style_list)
class LArrow(_Base):
class LArrow:
"""A box in the shape of a left-pointing arrow."""

def __init__(self, pad=0.3):
Expand Down Expand Up @@ -2441,7 +2365,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
return p

@_register_style(_style_list)
class DArrow(_Base):
class DArrow:
"""A box in the shape of a two-way arrow."""
# Modified from LArrow to add a right arrow to the bbox.

Expand Down Expand Up @@ -2478,7 +2402,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
closed=True)

@_register_style(_style_list)
class Round(_Base):
class Round:
"""A box with round corners."""

def __init__(self, pad=0.3, rounding_size=None):
Expand Down Expand Up @@ -2538,7 +2462,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
return path

@_register_style(_style_list)
class Round4(_Base):
class Round4:
"""A box with rounded edges."""

def __init__(self, pad=0.3, rounding_size=None):
Expand Down Expand Up @@ -2589,7 +2513,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
return path

@_register_style(_style_list)
class Sawtooth(_Base):
class Sawtooth:
"""A box with a sawtooth outline."""

def __init__(self, pad=0.3, tooth_size=None):
Expand Down Expand Up @@ -4025,11 +3949,9 @@ def set_boxstyle(self, boxstyle=None, **kwargs):
"""
if boxstyle is None:
return BoxStyle.pprint_styles()

if isinstance(boxstyle, BoxStyle._Base) or callable(boxstyle):
self._bbox_transmuter = boxstyle
else:
self._bbox_transmuter = BoxStyle(boxstyle, **kwargs)
self._bbox_transmuter = (
BoxStyle(boxstyle, **kwargs) if isinstance(boxstyle, str)
else boxstyle)
self.stale = True

def set_mutation_scale(self, scale):
Expand Down