diff --git a/doc/api/next_api_changes/behavior/27514-OG.rst b/doc/api/next_api_changes/behavior/27514-OG.rst new file mode 100644 index 000000000000..8b2a7ab9ef2e --- /dev/null +++ b/doc/api/next_api_changes/behavior/27514-OG.rst @@ -0,0 +1,5 @@ +Exception when not passing a Bbox to BboxTransform*-classes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The exception when not passing a Bbox to BboxTransform*-classes that expect one, e.g., +`~matplotlib.transforms.BboxTransform` has changed from ``ValueError`` to ``TypeError``. diff --git a/doc/api/next_api_changes/deprecations/27514-OG.rst b/doc/api/next_api_changes/deprecations/27514-OG.rst new file mode 100644 index 000000000000..f318ec8aa4bb --- /dev/null +++ b/doc/api/next_api_changes/deprecations/27514-OG.rst @@ -0,0 +1,4 @@ +``TransformNode.is_bbox`` +~~~~~~~~~~~~~~~~~~~~~~~~~ + +... is deprecated. Instead check the object using ``isinstance(..., BboxBase)``. diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 5a7fd125a29b..1a68ff12025f 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -102,7 +102,7 @@ class TransformNode: # Some metadata about the transform, used to determine whether an # invalidation is affine-only is_affine = False - is_bbox = False + is_bbox = _api.deprecated("3.9")(_api.classproperty(lambda cls: False)) pass_through = False """ @@ -220,7 +220,7 @@ class BboxBase(TransformNode): and height, but these are not stored explicitly. """ - is_bbox = True + is_bbox = _api.deprecated("3.9")(_api.classproperty(lambda cls: True)) is_affine = True if DEBUG: @@ -1101,8 +1101,7 @@ def __init__(self, bbox, transform, **kwargs): bbox : `Bbox` transform : `Transform` """ - if not bbox.is_bbox: - raise ValueError("'bbox' is not a bbox") + _api.check_isinstance(BboxBase, bbox=bbox) _api.check_isinstance(Transform, transform=transform) if transform.input_dims != 2 or transform.output_dims != 2: raise ValueError( @@ -1190,9 +1189,7 @@ def __init__(self, bbox, x0=None, y0=None, x1=None, y1=None, **kwargs): The locked value for y1, or None to leave unlocked. """ - if not bbox.is_bbox: - raise ValueError("'bbox' is not a bbox") - + _api.check_isinstance(BboxBase, bbox=bbox) super().__init__(**kwargs) self._bbox = bbox self.set_children(bbox) @@ -2547,8 +2544,7 @@ def __init__(self, boxin, boxout, **kwargs): Create a new `BboxTransform` that linearly transforms points from *boxin* to *boxout*. """ - if not boxin.is_bbox or not boxout.is_bbox: - raise ValueError("'boxin' and 'boxout' must be bbox") + _api.check_isinstance(BboxBase, boxin=boxin, boxout=boxout) super().__init__(**kwargs) self._boxin = boxin @@ -2591,8 +2587,7 @@ def __init__(self, boxout, **kwargs): Create a new `BboxTransformTo` that linearly transforms points from the unit bounding box to *boxout*. """ - if not boxout.is_bbox: - raise ValueError("'boxout' must be bbox") + _api.check_isinstance(BboxBase, boxout=boxout) super().__init__(**kwargs) self._boxout = boxout @@ -2645,8 +2640,7 @@ class BboxTransformFrom(Affine2DBase): is_separable = True def __init__(self, boxin, **kwargs): - if not boxin.is_bbox: - raise ValueError("'boxin' must be bbox") + _api.check_isinstance(BboxBase, boxin=boxin) super().__init__(**kwargs) self._boxin = boxin