Skip to content

Commit 7d09877

Browse files
committed
TYP: Add several missing return type annotations
1 parent 503432a commit 7d09877

35 files changed

+165
-133
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/_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:

lib/matplotlib/axis.pyi

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
from collections.abc import Callable, Iterable, Sequence
2+
import datetime
3+
from typing import Any, Literal, overload
4+
5+
import numpy as np
6+
from numpy.typing import ArrayLike
7+
18
import matplotlib.artist as martist
29
from matplotlib import cbook
310
from matplotlib.axes import Axes
@@ -6,12 +13,6 @@ from matplotlib.lines import Line2D
613
from matplotlib.text import Text
714
from matplotlib.ticker import Locator, Formatter
815
from matplotlib.transforms import Transform, Bbox
9-
10-
import datetime
11-
from collections.abc import Callable, Iterable, Sequence
12-
from typing import Any, Literal
13-
import numpy as np
14-
from numpy.typing import ArrayLike
1516
from matplotlib.typing import ColorType
1617

1718

@@ -92,7 +93,11 @@ class Ticker:
9293

9394
class _LazyTickList:
9495
def __init__(self, major: bool) -> None: ...
95-
def __get__(self, instance: Axis, cls: type): ...
96+
# Replace return with Self when py3.9 is dropped
97+
@overload
98+
def __get__(self, instance: None, owner: None) -> _LazyTickList: ...
99+
@overload
100+
def __get__(self, instance: Axis, owner: type[Axis]) -> list[Tick]: ...
96101

97102
class Axis(martist.Artist):
98103
OFFSETTEXTPAD: int

lib/matplotlib/backend_bases.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class RendererBase:
7676
facecolors: Sequence[ColorType],
7777
antialiased: bool,
7878
edgecolors: Sequence[ColorType] | ColorType | None,
79-
): ...
79+
) -> None: ...
8080
def draw_gouraud_triangle(
8181
self,
8282
gc: GraphicsContextBase,
@@ -321,7 +321,7 @@ class FigureCanvasBase:
321321
@property
322322
def scroll_pick_id(self) -> int: ...
323323
@classmethod
324-
def new_manager(cls, figure: Figure, num: int | str): ...
324+
def new_manager(cls, figure: Figure, num: int | str) -> FigureManagerBase: ...
325325
def is_saving(self) -> bool: ...
326326
def blit(self, bbox: BboxBase | None = ...) -> None: ...
327327
def inaxes(self, xy: tuple[float, float]) -> Axes | None: ...
@@ -351,7 +351,7 @@ class FigureCanvasBase:
351351
bbox_extra_artists: list[Artist] | None = ...,
352352
backend: str | None = ...,
353353
**kwargs
354-
): ...
354+
) -> Any: ...
355355
@classmethod
356356
def get_default_filetype(cls) -> str: ...
357357
def get_default_filename(self) -> str: ...
@@ -363,7 +363,7 @@ class FigureCanvasBase:
363363
self,
364364
interval: int | None = ...,
365365
callbacks: list[tuple[Callable, tuple, dict[str, Any]]] | None = ...,
366-
): ...
366+
) -> TimerBase: ...
367367
def flush_events(self) -> None: ...
368368
def start_event_loop(self, timeout: float = ...) -> None: ...
369369
def stop_event_loop(self) -> None: ...
@@ -372,7 +372,7 @@ def key_press_handler(
372372
event: KeyEvent,
373373
canvas: FigureCanvasBase | None = ...,
374374
toolbar: NavigationToolbar2 | None = ...,
375-
): ...
375+
) -> None: ...
376376
def button_press_handler(
377377
event: MouseEvent,
378378
canvas: FigureCanvasBase | None = ...,
@@ -392,7 +392,7 @@ class FigureManagerBase:
392392
@classmethod
393393
def create_with_canvas(
394394
cls, canvas_class: type[FigureCanvasBase], figure: Figure, num: int | str
395-
): ...
395+
) -> FigureManagerBase: ...
396396
@classmethod
397397
def start_main_loop(cls) -> None: ...
398398
@classmethod
@@ -476,9 +476,9 @@ class _Backend:
476476
FigureManager: type[FigureManagerBase]
477477
mainloop: None | Callable[[], Any]
478478
@classmethod
479-
def new_figure_manager(cls, num: int | str, *args, **kwargs): ...
479+
def new_figure_manager(cls, num: int | str, *args, **kwargs) -> FigureManagerBase: ...
480480
@classmethod
481-
def new_figure_manager_given_figure(cls, num: int | str, figure: Figure): ...
481+
def new_figure_manager_given_figure(cls, num: int | str, figure: Figure) -> FigureManagerBase: ...
482482
@classmethod
483483
def draw_if_interactive(cls) -> None: ...
484484
@classmethod
@@ -487,4 +487,4 @@ class _Backend:
487487
def export(cls) -> type[_Backend]: ...
488488

489489
class ShowBase(_Backend):
490-
def __call__(self, block: bool | None = ...): ...
490+
def __call__(self, block: bool | None = ...) -> None: ...

0 commit comments

Comments
 (0)