Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f250998

Browse files
authored
Merge pull request #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:

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: ...

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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
from collections.abc import Callable, Iterable, Sequence
2+
from typing import Literal
3+
4+
import numpy as np
5+
from numpy.typing import ArrayLike, NDArray
6+
17
from . import artist, cm, transforms
28
from .backend_bases import MouseEvent
39
from .artist import Artist
410
from .colors import Normalize, Colormap
11+
from .lines import Line2D
512
from .path import Path
613
from .patches import Patch
714
from .ticker import Locator, Formatter
815
from .tri import Triangulation
9-
10-
import numpy as np
11-
from numpy.typing import ArrayLike, NDArray
12-
from collections.abc import Callable, Iterable, Sequence
13-
from typing import Literal
1416
from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType
1517

1618
class Collection(artist.Artist, cm.ScalarMappable):
@@ -84,8 +86,8 @@ class PathCollection(_CollectionWithSizes):
8486
num: int | Literal["auto"] | ArrayLike | Locator = ...,
8587
fmt: str | Formatter | None = ...,
8688
func: Callable[[ArrayLike], ArrayLike] = ...,
87-
**kwargs
88-
): ...
89+
**kwargs,
90+
) -> tuple[list[Line2D], list[str]]: ...
8991

9092
class PolyCollection(_CollectionWithSizes):
9193
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: ...

0 commit comments

Comments
 (0)