Skip to content

Commit 53a97e9

Browse files
authored
Merge pull request #25710 from ksunden/bbox_intersect_return_type
TYP: Fix type hint (and docstring) for Bbox.intersection
2 parents 2c4f552 + fd62a2b commit 53a97e9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/matplotlib/artist.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,17 @@ def get_tightbbox(self, renderer=None):
361361
362362
Returns
363363
-------
364-
`.Bbox`
364+
`.Bbox` or None
365365
The enclosing bounding box (in figure pixel coordinates).
366+
Returns None if clipping results in no intersection.
366367
"""
367368
bbox = self.get_window_extent(renderer)
368369
if self.get_clip_on():
369370
clip_box = self.get_clip_box()
370371
if clip_box is not None:
371372
bbox = Bbox.intersection(bbox, clip_box)
372373
clip_path = self.get_clip_path()
373-
if clip_path is not None:
374+
if clip_path is not None and bbox is not None:
374375
clip_path = clip_path.get_fully_transformed_path()
375376
bbox = Bbox.intersection(bbox, clip_path.get_extents())
376377
return bbox

lib/matplotlib/transforms.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class BboxBase(TransformNode):
105105
@staticmethod
106106
def union(bboxes: Sequence[BboxBase]) -> Bbox: ...
107107
@staticmethod
108-
def intersection(bbox1: BboxBase, bbox2: BboxBase) -> Bbox: ...
108+
def intersection(bbox1: BboxBase, bbox2: BboxBase) -> Bbox | None: ...
109109

110110
class Bbox(BboxBase):
111111
def __init__(self, points: ArrayLike, **kwargs) -> None: ...

0 commit comments

Comments
 (0)