Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8001579

Browse files
authored
Merge pull request #23237 from anntzer/debase
Expire BoxStyle._Base deprecation.
2 parents f278686 + e5d6f58 commit 8001579

File tree

2 files changed

+18
-92
lines changed

2 files changed

+18
-92
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``BoxStyle._Base`` and ``transmute`` method of boxstyles
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... have been removed. Boxstyles implemented as classes no longer need to
4+
inherit from a base class.

lib/matplotlib/patches.py

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,94 +2268,18 @@ class BoxStyle(_Style):
22682268
22692269
%(AvailableBoxstyles)s
22702270
2271-
An instance of any boxstyle class is an callable object,
2272-
whose call signature is::
2271+
An instance of a boxstyle class is a callable object, with the signature ::
22732272
2274-
__call__(self, x0, y0, width, height, mutation_size)
2273+
__call__(self, x0, y0, width, height, mutation_size) -> Path
22752274
2276-
and returns a `.Path` instance. *x0*, *y0*, *width* and
2277-
*height* specify the location and size of the box to be
2278-
drawn. *mutation_scale* determines the overall size of the
2279-
mutation (by which I mean the transformation of the rectangle to
2280-
the fancy box).
2275+
*x0*, *y0*, *width* and *height* specify the location and size of the box
2276+
to be drawn; *mutation_size* scales the outline properties such as padding.
22812277
"""
22822278

22832279
_style_list = {}
22842280

2285-
@_api.deprecated("3.4")
2286-
class _Base:
2287-
"""
2288-
Abstract base class for styling of `.FancyBboxPatch`.
2289-
2290-
This class is not an artist itself. The `__call__` method returns the
2291-
`~matplotlib.path.Path` for outlining the fancy box. The actual drawing
2292-
is handled in `.FancyBboxPatch`.
2293-
2294-
Subclasses may only use parameters with default values in their
2295-
``__init__`` method because they must be able to be initialized
2296-
without arguments.
2297-
2298-
Subclasses must implement the `__call__` method. It receives the
2299-
enclosing rectangle *x0, y0, width, height* as well as the
2300-
*mutation_size*, which scales the outline properties such as padding.
2301-
It returns the outline of the fancy box as `.path.Path`.
2302-
"""
2303-
2304-
@_api.deprecated("3.4")
2305-
def transmute(self, x0, y0, width, height, mutation_size):
2306-
"""Return the `~.path.Path` outlining the given rectangle."""
2307-
return self(self, x0, y0, width, height, mutation_size, 1)
2308-
2309-
# This can go away once the deprecation period elapses, leaving _Base
2310-
# as a fully abstract base class just providing docstrings, no logic.
2311-
def __init_subclass__(cls):
2312-
transmute = _api.deprecate_method_override(
2313-
__class__.transmute, cls, since="3.4")
2314-
if transmute:
2315-
cls.__call__ = transmute
2316-
return
2317-
2318-
__call__ = cls.__call__
2319-
2320-
@_api.delete_parameter("3.4", "mutation_aspect")
2321-
def call_wrapper(
2322-
self, x0, y0, width, height, mutation_size,
2323-
mutation_aspect=_api.deprecation._deprecated_parameter):
2324-
if mutation_aspect is _api.deprecation._deprecated_parameter:
2325-
# Don't trigger deprecation warning internally.
2326-
return __call__(self, x0, y0, width, height, mutation_size)
2327-
else:
2328-
# Squeeze the given height by the aspect_ratio.
2329-
y0, height = y0 / mutation_aspect, height / mutation_aspect
2330-
path = self(x0, y0, width, height, mutation_size,
2331-
mutation_aspect)
2332-
vertices, codes = path.vertices, path.codes
2333-
# Restore the height.
2334-
vertices[:, 1] = vertices[:, 1] * mutation_aspect
2335-
return Path(vertices, codes)
2336-
2337-
cls.__call__ = call_wrapper
2338-
2339-
def __call__(self, x0, y0, width, height, mutation_size):
2340-
"""
2341-
Given the location and size of the box, return the path of
2342-
the box around it.
2343-
2344-
Parameters
2345-
----------
2346-
x0, y0, width, height : float
2347-
Location and size of the box.
2348-
mutation_size : float
2349-
A reference scale for the mutation.
2350-
2351-
Returns
2352-
-------
2353-
`~matplotlib.path.Path`
2354-
"""
2355-
raise NotImplementedError('Derived must override')
2356-
23572281
@_register_style(_style_list)
2358-
class Square(_Base):
2282+
class Square:
23592283
"""A square box."""
23602284

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

23802304
@_register_style(_style_list)
2381-
class Circle(_Base):
2305+
class Circle:
23822306
"""A circular box."""
23832307

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

24012325
@_register_style(_style_list)
2402-
class LArrow(_Base):
2326+
class LArrow:
24032327
"""A box in the shape of a left-pointing arrow."""
24042328

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

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

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

24802404
@_register_style(_style_list)
2481-
class Round(_Base):
2405+
class Round:
24822406
"""A box with round corners."""
24832407

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

25402464
@_register_style(_style_list)
2541-
class Round4(_Base):
2465+
class Round4:
25422466
"""A box with rounded edges."""
25432467

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

25912515
@_register_style(_style_list)
2592-
class Sawtooth(_Base):
2516+
class Sawtooth:
25932517
"""A box with a sawtooth outline."""
25942518

25952519
def __init__(self, pad=0.3, tooth_size=None):
@@ -4025,11 +3949,9 @@ def set_boxstyle(self, boxstyle=None, **kwargs):
40253949
"""
40263950
if boxstyle is None:
40273951
return BoxStyle.pprint_styles()
4028-
4029-
if isinstance(boxstyle, BoxStyle._Base) or callable(boxstyle):
4030-
self._bbox_transmuter = boxstyle
4031-
else:
4032-
self._bbox_transmuter = BoxStyle(boxstyle, **kwargs)
3952+
self._bbox_transmuter = (
3953+
BoxStyle(boxstyle, **kwargs) if isinstance(boxstyle, str)
3954+
else boxstyle)
40333955
self.stale = True
40343956

40353957
def set_mutation_scale(self, scale):

0 commit comments

Comments
 (0)