Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e19f283

Browse filesBrowse 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
Copy full SHA for e19f283
Expand file treeCollapse file tree

37 files changed

+211
-133
lines changed

‎lib/matplotlib/_path.pyi

Copy file name to clipboard
+2-2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/animation.pyi
+3-3Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.pyi
+6-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.pyi
+5-3Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.pyi
+4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.pyi
-4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.pyi
+1-2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_tools.pyi
+4-4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.pyi
+8-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.pyi
+3Lines 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__(

‎lib/matplotlib/colorbar.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.pyi
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import matplotlib.spines as mspines
22
from matplotlib import cbook, cm, collections, colors, contour, ticker
33
from matplotlib.axes import Axes
4+
from matplotlib.backend_bases import RendererBase
45
from matplotlib.patches import Patch
56
from matplotlib.ticker import Locator, Formatter
7+
from matplotlib.transforms import Bbox
68

79
import numpy as np
810
from numpy.typing import ArrayLike
@@ -12,6 +14,10 @@ from .typing import ColorType
1214

1315
class _ColorbarSpine(mspines.Spines):
1416
def __init__(self, axes: Axes): ...
17+
def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox:...
18+
def set_xy(self, xy: ArrayLike) -> None: ...
19+
def draw(self, renderer: RendererBase | None) -> None:...
20+
1521

1622
class Colorbar:
1723
n_rasterize: int

‎lib/matplotlib/colors.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.pyi
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,40 @@ def make_norm_from_scale(
187187
init: Callable | None = ...
188188
) -> Callable[[type[Normalize]], type[Normalize]]: ...
189189

190-
class FuncNorm(Normalize): ...
190+
class FuncNorm(Normalize):
191+
def __init__(
192+
self,
193+
functions: tuple[Callable, Callable],
194+
vmin: float | None = ...,
195+
vmax: float | None = ...,
196+
clip: bool = ...,
197+
) -> None: ...
191198
class LogNorm(Normalize): ...
192199

193200
class SymLogNorm(Normalize):
201+
def __init__(
202+
self,
203+
linthresh: float,
204+
linscale: float = ...,
205+
vmin: float | None = ...,
206+
vmax: float | None = ...,
207+
clip: bool = ...,
208+
*,
209+
base: float = ...,
210+
) -> None: ...
194211
@property
195212
def linthresh(self) -> float: ...
196213
@linthresh.setter
197214
def linthresh(self, value: float) -> None: ...
198215

199216
class AsinhNorm(Normalize):
217+
def __init__(
218+
self,
219+
linear_width: float = ...,
220+
vmin: float | None = ...,
221+
vmax: float | None = ...,
222+
clip: bool = ...,
223+
) -> None: ...
200224
@property
201225
def linear_width(self) -> float: ...
202226
@linear_width.setter

‎lib/matplotlib/figure.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.pyi
+23-14Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ class FigureBase(Artist):
125125
@overload
126126
def add_subplot(self, pos: int, **kwargs) -> Axes: ...
127127
@overload
128-
def add_subplot(self, ax: Axes) -> Axes: ...
128+
def add_subplot(self, ax: Axes, **kwargs) -> Axes: ...
129129
@overload
130-
def add_subplot(self) -> Axes: ...
130+
def add_subplot(self, ax: SubplotSpec, **kwargs) -> Axes: ...
131+
@overload
132+
def add_subplot(self, **kwargs) -> Axes: ...
131133
@overload
132134
def subplots(
133135
self,
@@ -159,14 +161,18 @@ class FigureBase(Artist):
159161
def delaxes(self, ax: Axes) -> None: ...
160162
def clear(self, keep_observers: bool = ...) -> None: ...
161163
def clf(self, keep_observers: bool = ...): ...
164+
162165
@overload
163166
def legend(self) -> Legend: ...
164167
@overload
165-
def legend(self, handles: Iterable[Artist], labels: Iterable[str]) -> Legend: ...
168+
def legend(self, handles: Iterable[Artist], labels: Iterable[str], **kwargs) -> Legend: ...
166169
@overload
167-
def legend(self, *, handles: Iterable[Artist]) -> Legend: ...
170+
def legend(self, *, handles: Iterable[Artist], **kwargs) -> Legend: ...
168171
@overload
169-
def legend(self, labels: Iterable[str]) -> Legend: ...
172+
def legend(self, labels: Iterable[str], **kwargs) -> Legend: ...
173+
@overload
174+
def legend(self, **kwargs) -> Legend: ...
175+
170176
def text(
171177
self,
172178
x: float,
@@ -185,12 +191,12 @@ class FigureBase(Artist):
185191
) -> Colorbar: ...
186192
def subplots_adjust(
187193
self,
188-
left: str | None = ...,
189-
bottom: str | None = ...,
190-
right: str | None = ...,
191-
top: str | None = ...,
192-
wspace: str | None = ...,
193-
hspace: str | None = ...,
194+
left: float | None = ...,
195+
bottom: float | None = ...,
196+
right: float | None = ...,
197+
top: float | None = ...,
198+
wspace: float | None = ...,
199+
hspace: float | None = ...,
194200
) -> None: ...
195201
def align_xlabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
196202
def align_ylabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
@@ -252,7 +258,7 @@ class FigureBase(Artist):
252258
class SubFigure(FigureBase):
253259
figure: FigureBase
254260
subplotpars: SubplotParams
255-
dpi_scale_trans: Transform
261+
dpi_scale_trans: Affine2D
256262
canvas: FigureCanvasBase
257263
transFigure: Transform
258264
bbox_relative: Bbox
@@ -288,7 +294,7 @@ class SubFigure(FigureBase):
288294

289295
class Figure(FigureBase):
290296
bbox_inches: Bbox
291-
dpi_scale_trans: Transform
297+
dpi_scale_trans: Affine2D
292298
bbox: Bbox
293299
figbbox: Bbox
294300
transFigure: Transform
@@ -315,7 +321,7 @@ class Figure(FigureBase):
315321
def pick(self, mouseevent: MouseEvent) -> None: ...
316322
def set_layout_engine(
317323
self,
318-
layout: Literal["constrained", "compressed", "tight"]
324+
layout: Literal["constrained", "compressed", "tight", "none"]
319325
| LayoutEngine
320326
| None = ...,
321327
**kwargs
@@ -330,6 +336,9 @@ class Figure(FigureBase):
330336
@dpi.setter
331337
def dpi(self, dpi: float) -> None: ...
332338
def get_tight_layout(self) -> bool: ...
339+
def get_constrained_layout_pads(
340+
self, relative: bool = ...
341+
) -> tuple[float, float, float, float]: ...
333342
def get_constrained_layout(self) -> bool: ...
334343
canvas: FigureCanvasBase
335344
def set_canvas(self, canvas: FigureCanvasBase) -> None: ...

‎lib/matplotlib/font_manager.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.pyi
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FontEntry:
3838
style: str = ...
3939
variant: str = ...
4040
weight: str = ...
41-
tretch: str = ...
41+
stretch: str = ...
4242
size: str = ...
4343

4444
def ttfFontProperty(font: ft2font.FT2Font) -> FontEntry: ...
@@ -87,6 +87,7 @@ def json_dump(data: FontManager, filename: str | Path | os.PathLike) -> None: ..
8787
def json_load(filename: str | Path | os.PathLike) -> FontManager: ...
8888

8989
class FontManager:
90+
__version__: int
9091
default_size: float | None
9192
defaultFamily: dict[str, str]
9293
afmlist: list[FontEntry]

‎lib/matplotlib/gridspec.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/gridspec.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GridSpecBase:
3434
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: ...
3535
@staticmethod
3636
def _check_gridspec_exists(figure, nrows, ncols): ...
37-
def __getitem__(self, key: tuple[int, int] | slice | int) -> SubplotSpec: ...
37+
def __getitem__(self, key: tuple[int | slice, int | slice] | slice | int) -> SubplotSpec: ...
3838
@overload
3939
def subplots(
4040
self,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.