From fd62a2b52389636c71d4ecc1ba0ca7d7a5630100 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Mon, 17 Apr 2023 14:57:54 -0500 Subject: [PATCH] TYP: Fix type hint (and docstring) for Bbox.intersection --- lib/matplotlib/artist.py | 5 +++-- lib/matplotlib/transforms.pyi | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 4eeaeeda441c..2356930429f0 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -361,8 +361,9 @@ def get_tightbbox(self, renderer=None): Returns ------- - `.Bbox` + `.Bbox` or None The enclosing bounding box (in figure pixel coordinates). + Returns None if clipping results in no intersection. """ bbox = self.get_window_extent(renderer) if self.get_clip_on(): @@ -370,7 +371,7 @@ def get_tightbbox(self, renderer=None): if clip_box is not None: bbox = Bbox.intersection(bbox, clip_box) clip_path = self.get_clip_path() - if clip_path is not None: + if clip_path is not None and bbox is not None: clip_path = clip_path.get_fully_transformed_path() bbox = Bbox.intersection(bbox, clip_path.get_extents()) return bbox diff --git a/lib/matplotlib/transforms.pyi b/lib/matplotlib/transforms.pyi index 37d51231084e..c199fbd88b2b 100644 --- a/lib/matplotlib/transforms.pyi +++ b/lib/matplotlib/transforms.pyi @@ -105,7 +105,7 @@ class BboxBase(TransformNode): @staticmethod def union(bboxes: Sequence[BboxBase]) -> Bbox: ... @staticmethod - def intersection(bbox1: BboxBase, bbox2: BboxBase) -> Bbox: ... + def intersection(bbox1: BboxBase, bbox2: BboxBase) -> Bbox | None: ... class Bbox(BboxBase): def __init__(self, points: ArrayLike, **kwargs) -> None: ...