From 01f1e9acde57144f4cd4b1aa805bbfbe8cfa2a76 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Fri, 5 Apr 2024 11:07:44 -0500 Subject: [PATCH] Be more specific in findobj return type When passing as a type, we know that the return contains only that type (and subtypes) --- lib/matplotlib/artist.pyi | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/artist.pyi b/lib/matplotlib/artist.pyi index 101e97a9a072..50f41b7f70e5 100644 --- a/lib/matplotlib/artist.pyi +++ b/lib/matplotlib/artist.pyi @@ -15,9 +15,11 @@ from .transforms import ( import numpy as np from collections.abc import Callable, Iterable -from typing import Any, NamedTuple, TextIO, overload +from typing import Any, NamedTuple, TextIO, overload, TypeVar from numpy.typing import ArrayLike +_T_Artist = TypeVar("_T_Artist", bound=Artist) + def allow_rasterization(draw): ... class _XYPair(NamedTuple): @@ -128,11 +130,21 @@ class Artist: def update(self, props: dict[str, Any]) -> list[Any]: ... def _internal_update(self, kwargs: Any) -> list[Any]: ... def set(self, **kwargs: Any) -> list[Any]: ... + + @overload def findobj( self, - match: None | Callable[[Artist], bool] | type[Artist] = ..., + match: None | Callable[[Artist], bool] = ..., include_self: bool = ..., ) -> list[Artist]: ... + + @overload + def findobj( + self, + match: type[_T_Artist], + include_self: bool = ..., + ) -> list[_T_Artist]: ... + def get_cursor_data(self, event: MouseEvent) -> Any: ... def format_cursor_data(self, data: Any) -> str: ... def get_mouseover(self) -> bool: ...