Skip to content

Commit e19f283

Browse files
committed
Address approx 100 issues identified by mypy.stubtest
A couple more stubtest found errors Fix typo in scale.pyi Updates to type hints from looking at mypy over tutorials Adjustments to type hints from inspecting examples Reorg legend overloads
1 parent eaa97fb commit e19f283

37 files changed

+211
-133
lines changed

lib/matplotlib/_path.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from collections.abc import Sequence
1+
from typing import Sequence
22
import numpy as np
33
from .transforms import BboxBase
44

5-
def affine_transform(points: np.ndarray, matrix: np.ndarray) -> np.ndarray: ...
5+
def affine_transform(points: np.ndarray, trans: np.ndarray) -> np.ndarray: ...
66
def count_bboxes_overlapping_bbox(a: BboxBase, bboxes: Sequence[BboxBase]) -> int: ...
77
def update_path_extents(*args, **kwargs): ...

lib/matplotlib/animation.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import abc
2-
from collections.abc import Callable, Iterable, Generator
2+
from collections.abc import Callable, Collection, Iterable, Sequence, Generator
33
import contextlib
44
from pathlib import Path
55
from matplotlib import cbook
@@ -207,15 +207,15 @@ class TimedAnimation(Animation):
207207
) -> None: ...
208208

209209
class ArtistAnimation(TimedAnimation):
210-
def __init__(self, fig: Figure, artists: list[Artist], *args, **kwargs) -> None: ...
210+
def __init__(self, fig: Figure, artists: Sequence[Collection[Artist]], *args, **kwargs) -> None: ...
211211

212212
class FuncAnimation(TimedAnimation):
213213
save_count: int
214214
def __init__(
215215
self,
216216
fig: Figure,
217217
func: Callable[..., Iterable[Artist]],
218-
frames: Iterable[Artist] | int | Generator[Artist, None, None] | None = ...,
218+
frames: Iterable[Artist] | int | Callable[[], Generator] | None = ...,
219219
init_func: Callable[[], Iterable[Artist]] | None = ...,
220220
fargs: tuple[Any, ...] | None = ...,
221221
save_count: int | None = ...,

lib/matplotlib/artist.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Artist:
128128
def get_zorder(self) -> float: ...
129129
def set_zorder(self, level: float) -> None: ...
130130
@property
131-
def sticky_edges(self) -> ArrayLike: ...
131+
def sticky_edges(self) -> _XYPair: ...
132132
def update_from(self, other: Artist) -> None: ...
133133
def properties(self) -> dict[str, Any]: ...
134134
def update(self, props: dict[str, Any]) -> Any: ...
@@ -144,6 +144,11 @@ class Artist:
144144
def get_mouseover(self) -> bool: ...
145145
def set_mouseover(self, mouseover: bool) -> None: ...
146146

147+
@property
148+
def mouseover(self) -> bool: ...
149+
@mouseover.setter
150+
def mouseover(self, mouseover: bool) -> None: ...
151+
147152
class ArtistInspector:
148153
oorig: Artist | type[Artist]
149154
o: type[Artist]

lib/matplotlib/axes/_axes.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ class Axes(_AxesBase):
5757
@overload
5858
def legend(self) -> Legend: ...
5959
@overload
60-
def legend(self, handles: Sequence[Artist], labels: Sequence[str]) -> Legend: ...
60+
def legend(self, handles: Sequence[Artist], labels: Sequence[str], **kwargs) -> Legend: ...
6161
@overload
62-
def legend(self, *, handles: Sequence[Artist]) -> Legend: ...
62+
def legend(self, *, handles: Sequence[Artist], **kwargs) -> Legend: ...
6363
@overload
64-
def legend(self, labels: Sequence[str]) -> Legend: ...
64+
def legend(self, labels: Sequence[str], **kwargs) -> Legend: ...
65+
@overload
66+
def legend(self, **kwargs) -> Legend: ...
6567

6668
def inset_axes(
6769
self,

lib/matplotlib/axes/_base.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ class _AxesBase(martist.Artist):
4848
yaxis: YAxis
4949
bbox: Bbox
5050
dataLim: Bbox
51+
transAxes: Transform
5152
transScale: Transform
53+
transLimits: Transform
54+
transData: Transform
5255
ignore_existing_data_limits: bool
5356
axison: bool
5457
_projection_init: Any
@@ -199,6 +202,7 @@ class _AxesBase(martist.Artist):
199202
def axis(
200203
self,
201204
arg: tuple[float, float, float, float] | bool | str | None = ...,
205+
/,
202206
*,
203207
emit: bool = ...
204208
) -> tuple[float, float, float, float]: ...

lib/matplotlib/axis.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class Tick(martist.Artist):
5454
def get_tick_padding(self) -> float: ...
5555
def get_children(self) -> list[martist.Artist]: ...
5656
stale: bool
57-
def get_pad_pixels(self) -> float: ...
5857
def set_pad(self, val: float) -> None: ...
5958
def get_pad(self) -> None: ...
6059
def get_loc(self) -> float: ...
@@ -165,7 +164,6 @@ class Axis(martist.Artist):
165164
def get_inverted(self) -> bool: ...
166165
def set_inverted(self, inverted: bool) -> None: ...
167166
def set_default_intervals(self) -> None: ...
168-
def get_ticklabel_extents(self, renderer: RendererBase) -> tuple[Bbox, Bbox]: ...
169167
def get_tightbbox(
170168
self, renderer: RendererBase | None = ..., *, for_layout_only: bool = ...
171169
) -> Bbox | None: ...
@@ -248,7 +246,6 @@ class XAxis(Axis):
248246
label_position: Literal["bottom", "top"]
249247
stale: bool
250248
def set_label_position(self, position: Literal["bottom", "top"]) -> None: ... # type: ignore[override]
251-
def get_text_heights(self, renderer: RendererBase) -> tuple[float, float]: ...
252249
def set_ticks_position(
253250
self, position: Literal["top", "bottom", "both", "default", "none"]
254251
) -> None: ...
@@ -265,7 +262,6 @@ class YAxis(Axis):
265262
stale: bool
266263
def set_label_position(self, position: Literal["left", "right"]) -> None: ... # type: ignore[override]
267264
def set_offset_position(self, position: Literal["left", "right"]) -> None: ...
268-
def get_text_widths(self, renderer: RendererBase) -> tuple[float, float]: ...
269265
def set_ticks_position(
270266
self, position: Literal["left", "right", "both", "default", "none"]
271267
) -> None: ...

lib/matplotlib/backend_bases.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ class FigureCanvasBase:
329329
@classmethod
330330
def new_manager(cls, figure: Figure, num: int | str): ...
331331
def is_saving(self) -> bool: ...
332-
def pick(self, mouseevent: MouseEvent) -> None: ...
333332
def blit(self, bbox: Bbox | None = ...) -> None: ...
334333
def inaxes(self, xy: tuple[float, float]) -> Axes | None: ...
335334
def grab_mouse(self, ax: Axes) -> None: ...
@@ -479,7 +478,7 @@ class ToolContainerBase:
479478

480479
class _Backend:
481480
backend_version: str
482-
FigureCanvas: type[FigureCanvasBase]
481+
FigureCanvas: type[FigureCanvasBase] | None
483482
FigureManager: type[FigureManagerBase]
484483
mainloop: None | Callable[[], Any]
485484
@classmethod

lib/matplotlib/backend_tools.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ class Cursors(enum.IntEnum):
2121
cursors = Cursors
2222

2323
class ToolBase:
24-
default_keymap: list[str] | None
24+
@property
25+
def default_keymap(self) -> list[str] | None: ...
2526
description: str | None
2627
image: str | None
2728
def __init__(self, toolmanager: ToolManager, name: str) -> None: ...
2829
@property
2930
def name(self) -> str: ...
3031
@property
31-
def toolmanger(self) -> ToolManager: ...
32+
def toolmanager(self) -> ToolManager: ...
3233
@property
3334
def canvas(self) -> FigureCanvasBase | None: ...
3435
@property
@@ -37,7 +38,6 @@ class ToolBase:
3738
def figure(self, figure: Figure | None) -> None: ...
3839
def set_figure(self, figure: Figure | None) -> None: ...
3940
def trigger(self, sender: Any, event: ToolEvent, data: Any = ...) -> None: ...
40-
def destroy(self) -> None: ...
4141

4242
class ToolToggleBase(ToolBase):
4343
radio_group: str | None
@@ -119,4 +119,4 @@ default_toolbar_tools: list[list[str | list[str]]]
119119
def add_tools_to_manager(
120120
toolmanager: ToolManager, tools: dict[str, type[ToolBase]] = ...
121121
) -> None: ...
122-
def add_tools_to_container(container: ToolContainerBase, tools: list[Any]) -> None: ...
122+
def add_tools_to_container(container: ToolContainerBase, tools: list[Any] = ...) -> None: ...

lib/matplotlib/cbook.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ def get_sample_data(
5959
fname: str | os.PathLike | io.FileIO,
6060
asfileobj: Literal[True] = ...,
6161
*,
62-
np_load: bool = ...
62+
np_load: Literal[True]
63+
) -> np.ndarray: ...
64+
@overload
65+
def get_sample_data(
66+
fname: str | os.PathLike | io.FileIO,
67+
asfileobj: Literal[True] = ...,
68+
*,
69+
np_load: Literal[False] = ...
6370
) -> io.FileIO: ...
6471
@overload
6572
def get_sample_data(

lib/matplotlib/collections.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ class LineCollection(Collection):
136136
def get_segments(self) -> list[np.ndarray]: ...
137137
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...
138138
def set_colors(self, c: ColorType | Sequence[ColorType]) -> None: ...
139+
def set_gapcolor(self, gapcolor: ColorType | Sequence[ColorType] | None) -> None: ...
139140
def get_color(self) -> ColorType | Sequence[ColorType]: ...
140141
def get_colors(self) -> ColorType | Sequence[ColorType]: ...
142+
def get_gapcolor(self) -> ColorType | Sequence[ColorType] | None: ...
143+
141144

142145
class EventCollection(LineCollection):
143146
def __init__(

0 commit comments

Comments
 (0)