8000 TYP: Add several missing return type annotations by QuLogic · Pull Request #26451 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

TYP: Add several missing return type annotations #26451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class RcParams(dict[str, Any]):
def __getitem__(self, key: str) -> Any: ...
def __iter__(self) -> Generator[str, None, None]: ...
def __len__(self) -> int: ...
def find_all(self, pattern: str): ...
def find_all(self, pattern: str) -> RcParams: ...
def copy(self) -> RcParams: ...

def rc_params(fail_on_error: bool = ...) -> RcParams: ...
Expand All @@ -96,7 +96,7 @@ def rc_file(
@contextlib.contextmanager
def rc_context(
rc: dict[str, Any] | None = ..., fname: str | Path | os.PathLike | None = ...
): ...
) -> Generator[None, None, None]: ...
def use(backend: str, *, force: bool = ...) -> None: ...
def get_backend() -> str: ...
def interactive(b: bool) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/_api/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class classproperty(Any):
fdel: None = ...,
doc: str | None = None,
): ...
# Replace return with Self when py3.9 is dropped
@overload
def __get__(self, instance: None, owner: None) -> classproperty: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/_enums.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum

class _AutoStringNameEnum(Enum):
def __hash__(self): ...
def __hash__(self) -> int: ...

class JoinStyle(str, _AutoStringNameEnum):
miter: str
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/animation.pyi
67ED
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AbstractMovieWriter(abc.ABC, metaclass=abc.ABCMeta):
dpi: float

@abc.abstractmethod
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...): ...
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...) -> None: ...
@property
def frame_size(self) -> tuple[int, int]: ...
@abc.abstractmethod
Expand All @@ -65,7 +65,7 @@ class MovieWriter(AbstractMovieWriter):
extra_args: list[str] | None = ...,
metadata: dict[str, str] | None = ...,
) -> None: ...
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...): ...
def setup(self, fig: Figure, outfile: str | Path, dpi: float | None = ...) -> None: ...
def grab_frame(self, **savefig_kwargs) -> None: ...
def finish(self) -> None: ...
@classmethod
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/artist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class Artist:
def set_clip_on(self, b: bool) -> None: ...
def get_rasterized(self) -> bool: ...
def set_rasterized(self, rasterized: bool) -> None: ...
def get_agg_filter(self): ...
def get_agg_filter(self) -> Callable[[ArrayLike, float], tuple[np.ndarray, float, float]] | None: ...
def set_agg_filter(
self, filter_func: Callable[[ArrayLike, float], tuple[np.ndarray, float, float]]
self, filter_func: Callable[[ArrayLike, float], tuple[np.ndarray, float, float]] | None
) -> None: ...
def draw(self, renderer: RendererBase) -> None: ...
def set_alpha(self, alpha: float | None) -> None: ...
Expand All @@ -125,9 +125,9 @@ class Artist:
def sticky_edges(self) -> _XYPair: ...
def update_from(self, other: Artist) -> None: ...
def properties(self) -> dict[str, Any]: ...
def update(self, props: dict[str, Any]) -> Any: ...
def _internal_update(self, kwargs): ...
def set(self, **kwargs: Any): ...
def update(self, props: dict[str, Any]) -> list[Any]: ...
def _internal_update(self, kwargs: Any) -> list[Any]: ...
def set(self, **kwargs: Any) -> list[Any]: ...
def findobj(
self,
match: None | Callable[[Artist], bool] | type[Artist] = ...,
Expand Down Expand Up @@ -177,5 +177,5 @@ def getp(obj: Artist, property: str | None = ...) -> Any: ...

get = getp

def setp(obj: Artist, *args, file: TextIO | None = ..., **kwargs): ...
def setp(obj: Artist, *args, file: TextIO | None = ..., **kwargs) -> list[Any] | None: ...
def kwdoc(artist: Artist | type[Artist] | Iterable[Artist | type[Artist]]) -> str: ...
7 changes: 5 additions & 2 deletions lib/matplotlib/axes/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from ._axes import *
from typing import TypeVar

from ._axes import *
from ._axes import Axes as Subplot

_T = TypeVar("_T")

class _SubplotBaseMeta(type):
def __instancecheck__(self, obj) -> bool: ...

class SubplotBase(metaclass=_SubplotBaseMeta): ...

def subplot_class_factory(cls): ...
def subplot_class_factory(cls: type[_T]) -> type[_T]: ...
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2745,8 +2745,8 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge",

Returns
-------
list of `.Text`
A list of `.Text` instances for the labels.
list of `.Annotation`
A list of `.Annotation` instances for the labels.
"""
for key in ['horizontalalignment', 'ha', 'verticalalignment', 'va']:
if key in kwargs:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Axes(_AxesBase):
label_type: Literal["center", "edge"] = ...,
padding: float = ...,
**kwargs
) -> list[Text]: ...
) -> list[Annotation]: ...
def broken_barh(
self,
xranges: Sequence[tuple[float, float]],
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/axes/_secondary_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class SecondaryAxis(_AxesBase):
) -> list[Tick]: ...
def set_functions(
self,
functions: tuple[
Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]
]
| Transform,
): ...
functions: tuple[Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]] | Transform,
) -> None: ...
def set_aspect(self, *args, **kwargs) -> None: ...
def set_color(self, color: ColorType) -> None: ...
2 changes: 1 addition & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class _LazyTickList:
def __init__(self, major):
self._major = major

def __get__(self, instance, cls):
def __get__(self, instance, owner):
if instance is None:
return self
else:
Expand Down
19 changes: 12 additions & 7 deletions lib/matplotlib/axis.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from collections.abc import Callable, Iterable, Sequence
import datetime
from typing import Any, Literal, overload

import numpy as np
from numpy.typing import ArrayLike

import matplotlib.artist as martist
from matplotlib import cbook
from matplotlib.axes import Axes
Expand All @@ -6,12 +13,6 @@ from matplotlib.lines import Line2D
from matplotlib.text import Text
from matplotlib.ticker import Locator, Formatter
from matplotlib.transforms import Transform, Bbox

import datetime
from collections.abc import Callable, Iterable, Sequence
from typing import Any, Literal
import numpy as np
from numpy.typing import ArrayLike
from matplotlib.typing import ColorType


Expand Down Expand Up @@ -92,7 +93,11 @@ class Ticker:

class _LazyTickList:
def __init__(self, major: bool) -> None: ...
def __get__(self, instance: Axis, cls: type): ...
# Replace return with Self when py3.9 is dropped
@overload
def __get__(self, instance: None, owner: None) -> _LazyTickList: ...
@overload
def __get__(self, instance: Axis, owner: type[Axis]) -> list[Tick]: ...

class Axis(martist.Artist):
OFFSETTEXTPAD: int
Expand Down
18 changes: 9 additions & 9 deletions lib/matplotlib/backend_bases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RendererBase:
facecolors: Sequence[ColorType],
antialiased: bool,
edgecolors: Sequence[ColorType] | ColorType | None,
): ...
) -> None: ...
def draw_gouraud_triangle(
self,
gc: GraphicsContextBase,
Expand Down Expand Up @@ -321,7 +321,7 @@ class FigureCanvasBase:
@property
def scroll_pick_id(self) -> int: ...
@classmethod
def new_manager(cls, figure: Figure, num: int | str): ...
def new_manager(cls, figure: Figure, num: int | str) -> FigureManagerBase: ...
def is_saving(self) -> bool: ...
def blit(self, bbox: BboxBase | None = ...) -> None: ...
def inaxes(self, xy: tuple[float, float]) -> Axes | None: ...
Expand Down Expand Up @@ -351,7 +351,7 @@ class FigureCanvasBase:
bbox_extra_artists: list[Artist] | None = ...,
backend: str | None = ...,
**kwargs
): ...
) -> Any: ...
@classmethod
def get_default_filetype(cls) -> str: ...
def get_default_filename(self) -> str: ...
Expand All @@ -363,7 +363,7 @@ class FigureCanvasBase:
self,
interval: int | None = ...,
callbacks: list[tuple[Callable, tuple, dict[str, Any]]] | None = ...,
): ...
) -> TimerBase: ...
def flush_events(self) -> None: ...
def start_event_loop(self, timeout: float = ...) -> None: ...
def stop_event_loop(self) -> None: ...
Expand All @@ -372,7 +372,7 @@ def key_press_handler(
event: KeyEvent,
canvas: FigureCanvasBase | None = ...,
toolbar: NavigationToolbar2 | None = ...,
): ...
) -> None: ...
def button_press_handler(
event: MouseEvent,
canvas: FigureCanvasBase | None = ...,
Expand All @@ -392,7 +392,7 @@ class FigureManagerBase:
@classmethod
def create_with_canvas(
cls, canvas_class: type[FigureCanvasBase], figure: Figure, num: int | str
): ...
) -> FigureManagerBase: ...
@classmethod
def start_main_loop(cls) -> None: ...
@classmethod
Expand Down Expand Up @@ -476,9 +476,9 @@ class _Backend:
FigureManager: type[FigureManagerBase]
mainloop: None | Callable[[], Any]
@classmethod
def new_figure_manager(cls, num: int | str, *args, **kwargs): ...
def new_figure_manager(cls, num: int | str, *args, **kwargs) -> FigureManagerBase: ...
@classmethod
def new_figure_manager_given_figure(cls, num: int | str, figure: Figure): ...
def new_figure_manager_given_figure(cls, num: int | str, figure: Figure) -> FigureManagerBase: ...
@classmethod
def draw_if_interactive(cls) -> None: ...
@classmethod
Expand All @@ -487,4 +487,4 @@ class _Backend:
def export(cls) -> type[_Backend]: ...

class ShowBase(_Backend):
def __call__(self, block: bool | None = ...): ...
def __call__(self, block: bool | None = ...) -> None: ...
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_managers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ToolManager:
def figure(self, figure: Figure) -> None: ...
def set_figure(self, figure: Figure, update_tools: bool = ...) -> None: ...
def toolmanager_connect(self, s: str, func: Callable[[ToolEvent], Any]) -> int: ...
def toolmanager_disconnect(self, cid: int): ...
def toolmanager_disconnect(self, cid: int) -> None: ...
def message_event(self, message: str, sender: Any | None = ...) -> None: ...
@property
def active_toggle(self) -> dict[str | None, list[str] | str]: ...
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/cm.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class ColormapRegistry(Mapping[str, colors.Colormap]):
self, cmap: colors.Colormap, *, name: str | None = ..., force: bool = ...
) -> None: ...
def unregister(self, name: str) -> None: ...
def get_cmap(self, cmap: str | colors.Colormap): ...
def get_cmap(self, cmap: str | colors.Colormap) -> colors.Colormap: ...

_colormaps: ColormapRegistry = ...
def get_cmap(name: str | colors.Colormap | None =..., lut: int | None =...): ...

def get_cmap(name: str | colors.Colormap | None = ..., lut: int | None = ...) -> colors.Colormap: ...

class ScalarMappable:
cmap: colors.Colormap | None
Expand Down
16 changes: 9 additions & 7 deletions lib/matplotlib/collections.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from collections.abc import Callable, Iterable, Sequence
from typing import Literal

import numpy as np
from numpy.typing import ArrayLike, NDArray

from . import artist, cm, transforms
from .backend_bases import MouseEvent
from .artist import Artist
from .colors import Normalize, Colormap
from .lines import Line2D
from .path import Path
from .patches import Patch
from .ticker import Locator, Formatter
from .tri import Triangulation

import numpy as np
from numpy.typing import ArrayLike, NDArray
from collections.abc import Callable, Iterable, Sequence
from typing import Literal
from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType

class Collection(artist.Artist, cm.ScalarMappable):
Expand Down Expand Up @@ -84,8 +86,8 @@ class PathCollection(_CollectionWithSizes):
num: int | Literal["auto"] | ArrayLike | Locator = ...,
fmt: str | Formatter | None = ...,
func: Callable[[ArrayLike], ArrayLike] = ...,
**kwargs
): ...
**kwargs,
) -> tuple[list[Line2D], list[str]]: ...

class PolyCollection(_CollectionWithSizes):
def __init__(
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/colorbar.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def make_axes(
shrink: float = ...,
aspect: float = ...,
**kwargs
): ...
) -> tuple[Axes, dict[str, Any]]: ...
def make_axes_gridspec(
parent: Axes,
*,
Expand All @@ -133,4 +133,4 @@ def make_axes_gridspec(
shrink: float = ...,
aspect: float = ...,
**kwargs
): ...
) -> tuple[Axes, dict[str, Any]]: ...
2 changes: 1 addition & 1 deletion lib/matplotlib/dviread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DviFont:

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

class Tfm:
checksum: int
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/gridspec.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GridSpecBase:
self, fig: Figure, raw: bool = ...
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: ...
@staticmethod
def _check_gridspec_exists(figure, nrows, ncols): ...
def _check_gridspec_exists(figure: Figure, nrows: int, ncols: int) -> GridSpec: ...
def __getitem__(
self, key: tuple[int | slice, int | slice] | slice | int
) -> SubplotSpec: ...
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/image.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class AxesImage(_ImageBase):
interpolation_stage: Literal["data", "rgba"] | None = ...,
**kwargs
) -> None: ...
def get_window_extent(self, renderer: RendererBase | None = ...): ...
def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ...
def make_image(
self, renderer: RendererBase, magnification: float = ..., unsampled: bool = ...
): ...
) -> tuple[np.ndarray, float, float, Affine2D]: ...
def set_extent(
self, extent: tuple[float, float, float, float], **kwargs
) -> None: ...
Expand Down
11 changes: 3 additions & 8 deletions lib/matplotlib/mathtext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ from matplotlib.typing import ColorType
class MathTextParser:
def __init__(self, output: Literal["path", "agg", "raster", "macosx"]) -> None: ...
def parse(
self,
s: str,
dpi: float = ...,
prop: FontProperties | None = ...,
*,
antialiased: bool | None = ...
): ...
self, s: str, dpi: float = ..., prop: FontProperties | None = ..., *, antialiased: bool | None = ...
) -> RasterParse | VectorParse: ...

def math_to_image(
s: str,
Expand All @@ -30,4 +25,4 @@ def math_to_image(
format: str | None = ...,
*,
color: ColorType | None = ...
): ...
) -> float: ...
Loading
0