8000 Merge pull request #27514 from oscargus/bboxcheck · matplotlib/matplotlib@65d6560 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65d6560

Browse files
authored
Merge pull request #27514 from oscargus/bboxcheck
Improve check for bbox
2 parents 091e2ca + 24a7468 commit 65d6560

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Exception when not passing a Bbox to BboxTransform*-classes
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The exception when not passing a Bbox to BboxTransform*-classes that expect one, e.g.,
5+
`~matplotlib.transforms.BboxTransform` has changed from ``ValueError`` to ``TypeError``.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``TransformNode.is_bbox``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... is deprecated. Instead check the object using ``isinstance(..., BboxBase)``.

lib/matplotlib/transforms.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class TransformNode:
102102
# Some metadata about the transform, used to determine whether an
103103
# invalidation is affine-only
104104
is_affine = False
105-
is_bbox = False
105+
is_bbox = _api.deprecated("3.9")(_api.classproperty(lambda cls: False))
106106

107107
pass_through = False
108108
"""
@@ -220,7 +220,7 @@ class BboxBase(TransformNode):
220220
and height, but these are not stored explicitly.
221221
"""
222222

223-
is_bbox = True
223+
is_bbox = _api.deprecated("3.9")(_api.classproperty(lambda cls: True))
224224
is_affine = True
225225

226226
if DEBUG:
@@ -1101,8 +1101,7 @@ def __init__(self, bbox, transform, **kwargs):
11011101
bbox : `Bbox`
11021102
transform : `Transform`
11031103
"""
1104-
if not bbox.is_bbox:
1105-
raise ValueError("'bbox' is not a bbox")
1104+
_api.check_isinstance(BboxBase, bbox=bbox)
11061105
_api.check_isinstance(Transform, transform=transform)
11071106
if transform.input_dims != 2 or transform.output_dims != 2:
11081107
raise ValueError(
@@ -1190,9 +1189,7 @@ def __init__(self, bbox, x0=None, y0=None, x1=None, y1=None, **kwargs):
11901189
The locked value for y1, or None to leave unlocked.
11911190
11921191
"""
1193-
if not bbox.is_bbox:
1194-
raise ValueError("'bbox' is not a bbox")
1195-
1192+
_api.check_isinstance(BboxBase, bbox=bbox)
11961193
super().__init__(**kwargs)
11971194
self._bbox = bbox
11981195
self.set_children(bbox)
@@ -2547,8 +2544,7 @@ def __init__(self, boxin, boxout, **kwargs):
25472544
Create a new `BboxTransform` that linearly transforms
25482545
points from *boxin* to *boxout*.
25492546
"""
2550-
if not boxin.is_bbox or not boxout.is_bbox:
2551-
raise ValueError("'boxin' and 'boxout' must be bbox")
2547+
_api.check_isinstance(BboxBase, boxin=boxin, boxout=boxout)
25522548

25532549
super().__init__(**kwargs)
25542550
self._boxin = boxin
@@ -2591,8 +2587,7 @@ def __init__(self, boxout, **kwargs):
25912587
Create a new `BboxTransformTo` that linearly transforms
25922588
points from the unit bounding box to *boxout*.
25932589
"""
2594-
if not boxout.is_bbox:
2595-
raise ValueError("'boxout' must be bbox")
2590+
_api.check_isinstance(BboxBase, boxout=boxout)
25962591

25972592
super().__init__(**kwargs)
25982593
self._boxout = boxout
@@ -2646,8 +2641,7 @@ class BboxTransformFrom(Affine2DBase):
26462641
is_separable = True
26472642

26482643
def __init__(self, boxin, **kwargs):
2649-
if not boxin.is_bbox:
2650-
raise ValueError("'boxin' must be bbox")
2644+
_api.check_isinstance(BboxBase, boxin=boxin)
26512645

26522646
super().__init__(**kwargs)
26532647
self._boxin = boxin

0 commit comments

Comments
 (0)
0