8000 TYP: Add several missing return type annotations · matplotlib/matplotlib@32f9870 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32f9870

Browse files
committed
TYP: Add several missing return type annotations
1 parent 440f761 commit 32f9870

32 files changed

+144
-120
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/_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
10000
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/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: ...

lib/matplotlib/backend_managers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ToolManager:
4141
def figure(self, figure: Figure) -> None: ...
4242
def set_figure(self, figure: Figure, update_tools: bool = ...) -> None: ...
4343
def toolmanager_connect(self, s: str, func: Callable[[ToolEvent], Any]) -> int: ...
44-
def toolmanager_disconnect(self, cid: int): ...
44+
def toolmanager_disconnect(self, cid: int) -> None: ...
4545
def message_event(self, message: str, sender: Any | None = ...) -> None: ...
4646
@property
4747
def active_toggle(self) -> dict[str | None, list[str] | str]: ...

lib/matplotlib/cm.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class ColormapRegistry(Mapping[str, colors.Colormap]):
1515
self, cmap: colors.Colormap, *, name: str | None = ..., force: bool = ...
1616
) -> None: ...
1717
def unregister(self, name: str) -> None: ...
18-
def get_cmap(self, cmap: str | colors.Colormap): ...
18+
def get_cmap(self, cmap: str | colors.Colormap) -> colors.Colormap: ...
1919

2020
_colormaps: ColormapRegistry = ...
21-
def get_cmap(name: str | colors.Colormap | None =..., lut: int | None =...): ...
21+
22+
def get_cmap(name: str | colors.Colormap | None = ..., lut: int | None = ...) -> colors.Colormap: ...
2223

2324
class ScalarMappable:
2425
cmap: colors.Colormap | None

lib/matplotlib/collections.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class PathCollection(_CollectionWithSizes):
8484
num: int | Literal["auto"] | ArrayLike | Locator = ...,
8585
fmt: str | Formatter | None = ...,
8686
func: Callable[[ArrayLike], ArrayLike] = ...,
87-
**kwargs
88-
): ...
87+
**kwargs,
88+
) -> tuple[list[Artist], list[str]]: ...
8989

9090
class PolyCollection(_CollectionWithSizes):
9191
def __init__(

lib/matplotlib/colorbar.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def make_axes(
123123
shrink: float = ...,
124124
aspect: float = ...,
125125
**kwargs
126-
): ...
126+
) -> tuple[Axes, dict[str, Any]]: ...
127127
def make_axes_gridspec(
128128
parent: Axes,
129129
*,
@@ -133,4 +133,4 @@ def make_axes_gridspec(
133133
shrink: float = ...,
134134
aspect: float = ...,
135135
**kwargs
136-
): ...
136+
) -> tuple[Axes, dict[str, Any]]: ...

lib/matplotlib/dviread.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DviFont:
6565

6666
class Vf(Dvi):
6767
def __init__(self, filename: str | os.PathLike) -> None: ...
68-
def __getitem__(self, code: int): ...
68+
def __getitem__(self, code: int) -> Page: ...
6969

7070
class Tfm:
7171
checksum: int

lib/matplotlib/gridspec.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GridSpecBase:
3333
self, fig: Figure, raw: bool = ...
3434
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: ...
3535
@staticmethod
36-
def _check_gridspec_exists(figure, nrows, ncols): ...
36+
def _check_gridspec_exists(figure: Figure, nrows: int, ncols: int) -> GridSpec: ...
3737
def __getitem__(
3838
self, key: tuple[int | slice, int | slice] | slice | int
3939
) -> SubplotSpec: ...

lib/matplotlib/image.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ class AxesImage(_ImageBase):
114114
interpolation_stage: Literal["data", "rgba"] | None = ...,
115115
**kwargs
116116
) -> None: ...
117-
def get_window_extent(self, renderer: RendererBase | None = ...): ...
117+
def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ...
118118
def make_image(
119119
self, renderer: RendererBase, magnification: float = ..., unsampled: bool = ...
120-
): ...
120+
) -> tuple[np.ndarray, float, float, Affine2D]: ...
121121
def set_extent(
122122
self, extent: tuple[float, float, float, float], **kwargs
123123
) -> None: ...

lib/matplotlib/mathtext.pyi

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ from matplotlib.typing import ColorType
1414
class MathTextParser:
1515
def __init__(self, output: Literal["path", "agg", "raster", "macosx"]) -> None: ...
1616
def parse(
17-
self,
18-
s: str,
19-
dpi: float = ...,
20-
prop: FontProperties | None = ...,
21-
*,
22-
antialiased: bool | None = ...
23-
): ...
17+
self, s: str, dpi: float = ..., prop: FontProperties | None = ..., *, antialiased: bool | None = ...
18+
) -> RasterParse | VectorParse: ...
2419

2520
def math_to_image(
2621
s: str,
@@ -30,4 +25,4 @@ def math_to_image(
3025
format: str | None = ...,
3126
*,
3227
color: ColorType | None = ...
33-
): ...
28+
) -> float: ...

lib/matplotlib/mlab.pyi

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def detrend(
1313
| Callable[[ArrayLike, int | None], ArrayLike]
1414
| None = ...,
1515
axis: int | None = ...,
16-
): ...
16+
) -> ArrayLike: ...
1717
def detrend_mean(x: ArrayLike, axis: int | None = ...) -> ArrayLike: ...
1818
def detrend_none(x: ArrayLike, axis: int | None = ...) -> ArrayLike: ...
1919
def detrend_linear(y: ArrayLike) -> ArrayLike: ...
@@ -54,29 +54,26 @@ def specgram(
5454
x: ArrayLike,
5555
NFFT: int | None = ...,
5656
Fs: float | None = ...,
57-
detrend: Literal["none", "mean", "linear"]
58-
| Callable[[ArrayLike, int | None], ArrayLike]
59-
| None = ...,
57+
detrend: Literal["none", "mean", "linear"] | Callable[[ArrayLike, int | None], ArrayLike] | None = ...,
6058
window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ...,
6159
noverlap: int | None = ...,
6260
pad_to: int | None = ...,
6361
sides: Literal["default", "onesided", "twosided"] | None = ...,
6462
scale_by_freq: bool | None = ...,
6563
mode: Literal["psd", "complex", "magnitude", "angle", "phase"] | None = ...,
66-
): ...
64+
) -> tuple[ArrayLike, ArrayLike, ArrayLike]: ...
6765
def cohere(
6866
x: ArrayLike,
6967
y: ArrayLike,
7068
NFFT: int = ...,
7169
Fs: float = ...,
72-
detrend: Literal["none", "mean", "linear"]
73-
| Callable[[ArrayLike, int | None], ArrayLike] = ...,
70+
detrend: Literal["none", "mean", "linear"] | Callable[[ArrayLike, int | None], ArrayLike] = ...,
7471
window: Callable[[ArrayLike], ArrayLike] | ArrayLike = ...,
7572
noverlap: int = ...,
7673
pad_to: int | None = ...,
7774
sides: Literal["default", "onesided", "twosided"] = ...,
7875
scale_by_freq: bool | None = ...,
79-
): ...
76+
) -> tuple[ArrayLike, ArrayLike]: ...
8077

8178
class GaussianKDE:
8279
dataset: ArrayLike

lib/matplotlib/patches.pyi

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Patch(artist.Artist):
2828
**kwargs,
2929
) -> None: ...
3030
def get_verts(self) -> ArrayLike: ...
31-
def contains(self, mouseevent: MouseEvent, radius: float | None = None): ...
31+
def contains(self, mouseevent: MouseEvent, radius: float | None = None) -> tuple[bool, dict[Any, Any]]: ...
3232
def contains_point(
3333
self, point: tuple[float, float], radius: float | None = ...
3434
) -> bool: ...
@@ -287,7 +287,7 @@ class Circle(Ellipse):
287287
self, xy: tuple[float, float], radius: float = ..., **kwargs
288288
) -> None: ...
289289
def set_radius(self, radius: float) -> None: ...
290-
def get_radius(self): ...
290+
def get_radius(self) -> float: ...
291291
radius = property(get_radius, set_radius)
292292

293293
class Arc(Ellipse):
@@ -663,7 +663,7 @@ class FancyBboxPatch(Patch):
663663
mutation_aspect: float = ...,
664664
**kwargs,
665665
) -> None: ...
666-
def set_boxstyle(self, boxstyle: str | BoxStyle | None = ..., **kwargs): ...
666+
def set_boxstyle(self, boxstyle: str | BoxStyle | None = ..., **kwargs) -> None: ...
667667
def get_boxstyle(self) -> BoxStyle: ...
668668
def set_mutation_scale(self, scale: float) -> None: ...
669669
def get_mutation_scale(self) -> float: ...
@@ -711,11 +711,9 @@ class FancyArrowPatch(Patch):
711711
) -> None: ...
712712
def set_patchA(self, patchA: Patch) -> None: ...
713713
def set_patchB(self, patchB: Patch) -> None: ...
714-
def set_connectionstyle(
715-
self, connectionstyle: str | ConnectionStyle | None = ..., **kwargs
716-
): ...
714+
def set_connectionstyle(self, connectionstyle: str | ConnectionStyle | None = ..., **kwargs) -> None: ...
717715
def get_connectionstyle(self) -> ConnectionStyle: ...
718-
def set_arrowstyle(self, arrowstyle: str | ArrowStyle | None = ..., **kwargs): ...
716+
def set_arrowstyle(self, arrowstyle: str | ArrowStyle | None = ..., **kwargs) -> None: ...
719717
def get_arrowstyle(self) -> ArrowStyle: ...
720718
def set_mutation_scale(self, scale: float) -> None: ...
721719
def get_mutation_scale(self) -> float: ...

lib/matplotlib/path.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Path:
4444
@property
4545
def readonly(self) -> bool: ...
4646
def copy(self) -> Path: ...
47-
def __deepcopy__(self, memo: dict[int, Any] | None = ...): ...
47+
def __deepcopy__(self, memo: dict[int, Any] | None = ...) -> Path: ...
4848
deepcopy = __deepcopy__
4949

5050
@classmethod

0 commit comments

Comments
 (0)
0