Skip to content

Commit f250998

Browse files
authored
Merge pull request matplotlib#26451 from QuLogic/type-return
TYP: Add several missing return type annotations
2 parents 2cbb3e0 + 371f41d commit f250998

39 files changed

+205
-173
lines changed

lib/matplotlib/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RcParams(dict[str, Any]):
7272
def __getitem__(self, key: str) -> Any: ...
7373
def __iter__(self) -> Generator[str, None, None]: ...
7474
def __len__(self) -> int: ...
75-
def find_all(self, pattern: str): ...
75+
def find_all(self, pattern: str) -> RcParams: ...
7676
def copy(self) -> RcParams: ...
7777

7878
def rc_params(fail_on_error: bool = ...) -> RcParams: ...
@@ -96,7 +96,7 @@ def rc_file(
9696
@contextlib.contextmanager
9797
def rc_context(
9898
rc: dict[str, Any] | None = ..., fname: str | Path | os.PathLike | None = ...
99-
): ...
99+
) -> Generator[None, None, None]: ...
100100
def use(backend: str, *, force: bool = ...) -> None: ...
101101
def get_backend() -> str: ...
102102
def interactive(b: bool) -> None: ...

lib/matplotlib/_api/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class classproperty(Any):
2525
fdel: None = ...,
2626
doc: str | None = None,
2727
): ...
28+
# Replace return with Self when py3.9 is dropped
2829
@overload
2930
def __get__(self, instance: None, owner: None) -> classproperty: ...
3031
@overload

lib/matplotlib/_enums.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from enum import Enum
22

33
class _AutoStringNameEnum(Enum):
4-
def __hash__(self): ...
4+
def __hash__(self) -> int: ...
55

66
class JoinStyle(str, _AutoStringNameEnum):
77
miter: str

lib/matplotlib/animation.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AbstractMovieWriter(abc.ABC, metaclass=abc.ABCMeta):
4141
dpi: float
4242

4343
@abc.abstractmethod
44-
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...): ...
44+
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...) -> None: ...
4545
@property
4646
def frame_size(self) -> tuple[int, int]: ...
4747
@abc.abstractmethod
@@ -65,7 +65,7 @@ class MovieWriter(AbstractMovieWriter):
6565
extra_args: list[str] | None = ...,
6666
metadata: dict[str, str] | None = ...,
6767
) -> None: ...
68-
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...): ...
68+
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...) -> None: ...
6969
def grab_frame(self, **savefig_kwargs) -> None: ...
7070
def finish(self) -> None: ...
7171
@classmethod

lib/matplotlib/artist.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ class Artist:
108108
def set_clip_on(self, b: bool) -> None: ...
109109
def get_rasterized(self) -> bool: ...
110110
def set_rasterized(self, rasterized: bool) -> None: ...
111-
def get_agg_filter(self): ...
111+
def get_agg_filter(self) -> Callable[[ArrayLike, float], tuple[np.ndarray, float, float]] | None: ...
112112
def set_agg_filter(
113-
self, filter_func: Callable[[ArrayLike, float], tuple[np.ndarray, float, float]]
113+
self, filter_func: Callable[[ArrayLike, float], tuple[np.ndarray, float, float]] | None
114114
) -> None: ...
115115
def draw(self, renderer: RendererBase) -> None: ...
116116
def set_alpha(self, alpha: float | None) -> None: ...
@@ -125,9 +125,9 @@ class Artist:
125125
def sticky_edges(self) -> _XYPair: ...
126126
def update_from(self, other: Artist) -> None: ...
127127
def properties(self) -> dict[str, Any]: ...
128-
def update(self, props: dict[str, Any]) -> Any: ...
129-
def _internal_update(self, kwargs): ...
130-
def set(self, **kwargs: Any): ...
128+
def update(self, props: dict[str, Any]) -> list[Any]: ...
129+
def _internal_update(self, kwargs: Any) -> list[Any]: ...
130+
def set(self, **kwargs: Any) -> list[Any]: ...
131131
def findobj(
132132
self,
133133
match: None | Callable[[Artist], bool] | type[Artist] = ...,
@@ -177,5 +177,5 @@ def getp(obj: Artist, property: str | None = ...) -> Any: ...
177177

178178
get = getp
179179

180-
def setp(obj: Artist, *args, file: TextIO | None = ..., **kwargs): ...
180+
def setp(obj: Artist, *args, file: TextIO | None = ..., **kwargs) -> list[Any] | None: ...
181181
def kwdoc(artist: Artist | type[Artist] | Iterable[Artist | type[Artist]]) -> str: ...

lib/matplotlib/axes/__init__.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from ._axes import *
1+
from typing import TypeVar
22

3+
from ._axes import *
34
from ._axes import Axes as Subplot
45

6+
_T = TypeVar("_T")
7+
58
class _SubplotBaseMeta(type):
69
def __instancecheck__(self, obj) -> bool: ...
710

811
class SubplotBase(metaclass=_SubplotBaseMeta): ...
912

10-
def subplot_class_factory(cls): ...
13+
def subplot_class_factory(cls: type[_T]) -> type[_T]: ...

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,8 +2745,8 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge",
27452745
27462746
Returns
27472747
-------
2748-
list of `.Text`
2749-
A list of `.Text` instances for the labels.
2748+
list of `.Annotation`
2749+
A list of `.Annotation` instances for the labels.
27502750
"""
27512751
for key in ['horizontalalignment', 'ha', 'verticalalignment', 'va']:
27522752
if key in kwargs:

lib/matplotlib/axes/_axes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class Axes(_AxesBase):
274274
label_type: Literal["center", "edge"] = ...,
275275
padding: float = ...,
276276
**kwargs
277-
) -> list[Text]: ...
277+
) -> list[Annotation]: ...
278278
def broken_barh(
279279
self,
280280
xranges: Sequence[tuple[float, float]],

lib/matplotlib/axes/_secondary_axes.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ class SecondaryAxis(_AxesBase):
3636
) -> list[Tick]: ...
3737
def set_functions(
3838
self,
39-
functions: tuple[
40-
Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]
41-
]
42-
| Transform,
43-
): ...
39+
functions: tuple[Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]] | Transform,
40+
) -> None: ...
4441
def set_aspect(self, *args, **kwargs) -> None: ...
4542
def set_color(self, color: ColorType) -> None: ...

lib/matplotlib/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ class _LazyTickList:
572572
def __init__(self, major):
573573
self._major = major
574574

575-
def __get__(self, instance, cls):
575+
def __get__(self, instance, owner):
576576
if instance is None:
577577
return self
578578
else:

0 commit comments

Comments
 (0)