From 7d09877e01c02fe6114e08dc6c7bbea00635be34 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 3 Aug 2023 17:07:34 -0400 Subject: [PATCH 1/3] TYP: Add several missing return type annotations --- lib/matplotlib/__init__.pyi | 4 +-- lib/matplotlib/_api/__init__.pyi | 1 + lib/matplotlib/_enums.pyi | 2 +- lib/matplotlib/animation.pyi | 4 +-- lib/matplotlib/artist.pyi | 12 +++---- lib/matplotlib/axes/__init__.pyi | 7 ++-- lib/matplotlib/axes/_secondary_axes.pyi | 7 ++-- lib/matplotlib/axis.py | 2 +- lib/matplotlib/axis.pyi | 19 +++++++---- lib/matplotlib/backend_bases.pyi | 18 +++++----- lib/matplotlib/backend_managers.pyi | 2 +- lib/matplotlib/cm.pyi | 5 +-- lib/matplotlib/collections.pyi | 16 +++++---- lib/matplotlib/colorbar.pyi | 4 +-- lib/matplotlib/dviread.pyi | 2 +- lib/matplotlib/gridspec.pyi | 2 +- lib/matplotlib/image.pyi | 4 +-- lib/matplotlib/mathtext.pyi | 11 ++----- lib/matplotlib/mlab.pyi | 13 +++----- lib/matplotlib/patches.pyi | 12 +++---- lib/matplotlib/path.pyi | 2 +- lib/matplotlib/patheffects.pyi | 8 +++-- lib/matplotlib/projections/polar.pyi | 6 ++-- lib/matplotlib/pyplot.py | 44 ++++++++++++------------- lib/matplotlib/sankey.pyi | 3 +- lib/matplotlib/scale.pyi | 2 +- lib/matplotlib/spines.pyi | 8 ++--- lib/matplotlib/table.pyi | 4 +-- lib/matplotlib/text.pyi | 4 +-- lib/matplotlib/ticker.pyi | 10 +++--- lib/matplotlib/transforms.pyi | 14 ++++---- lib/matplotlib/tri/_triangulation.pyi | 2 +- lib/matplotlib/tri/_tripcolor.pyi | 40 +++++++++++++++++++--- lib/matplotlib/widgets.pyi | 2 +- tools/boilerplate.py | 2 +- 35 files changed, 165 insertions(+), 133 deletions(-) diff --git a/lib/matplotlib/__init__.pyi b/lib/matplotlib/__init__.pyi index 9ccb8fe9854c..8ef23a3dc4c2 100644 --- a/lib/matplotlib/__init__.pyi +++ b/lib/matplotlib/__init__.pyi @@ -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: ... @@ -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: ... diff --git a/lib/matplotlib/_api/__init__.pyi b/lib/matplotlib/_api/__init__.pyi index 84a712d300fa..4baff7cd804c 100644 --- a/lib/matplotlib/_api/__init__.pyi +++ b/lib/matplotlib/_api/__init__.pyi @@ -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 diff --git a/lib/matplotlib/_enums.pyi b/lib/matplotlib/_enums.pyi index 3dc8329135ff..351088b36453 100644 --- a/lib/matplotlib/_enums.pyi +++ b/lib/matplotlib/_enums.pyi @@ -1,7 +1,7 @@ from enum import Enum class _AutoStringNameEnum(Enum): - def __hash__(self): ... + def __hash__(self) -> int: ... class JoinStyle(str, _AutoStringNameEnum): miter: str diff --git a/lib/matplotlib/animation.pyi b/lib/matplotlib/animation.pyi index d13496a0af57..de1b9926afd6 100644 --- a/lib/matplotlib/animation.pyi +++ b/lib/matplotlib/animation.pyi @@ -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 @@ -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 diff --git a/lib/matplotlib/artist.pyi b/lib/matplotlib/artist.pyi index 72972e2f1f69..101e97a9a072 100644 --- a/lib/matplotlib/artist.pyi +++ b/lib/matplotlib/artist.pyi @@ -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: ... @@ -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] = ..., @@ -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: ... diff --git a/lib/matplotlib/axes/__init__.pyi b/lib/matplotlib/axes/__init__.pyi index 0b10c3b0f648..0c27be62e370 100644 --- a/lib/matplotlib/axes/__init__.pyi +++ b/lib/matplotlib/axes/__init__.pyi @@ -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]: ... diff --git a/lib/matplotlib/axes/_secondary_axes.pyi b/lib/matplotlib/axes/_secondary_axes.pyi index fdb261d9f64c..dcf1d2eb7723 100644 --- a/lib/matplotlib/axes/_secondary_axes.pyi +++ b/lib/matplotlib/axes/_secondary_axes.pyi @@ -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: ... diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index face653c5566..0ace31916ca9 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -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: diff --git a/lib/matplotlib/axis.pyi b/lib/matplotlib/axis.pyi index fe781d380e3e..5ca8fcb6fd6c 100644 --- a/lib/matplotlib/axis.pyi +++ b/lib/matplotlib/axis.pyi @@ -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 @@ -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 @@ -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 diff --git a/lib/matplotlib/backend_bases.pyi b/lib/matplotlib/backend_bases.pyi index 221c984ac90d..0ae88cf18a42 100644 --- a/lib/matplotlib/backend_bases.pyi +++ b/lib/matplotlib/backend_bases.pyi @@ -76,7 +76,7 @@ class RendererBase: facecolors: Sequence[ColorType], antialiased: bool, edgecolors: Sequence[ColorType] | ColorType | None, - ): ... + ) -> None: ... def draw_gouraud_triangle( self, gc: GraphicsContextBase, @@ -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: ... @@ -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: ... @@ -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: ... @@ -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 = ..., @@ -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 @@ -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 @@ -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: ... diff --git a/lib/matplotlib/backend_managers.pyi b/lib/matplotlib/backend_managers.pyi index fbeb460097c3..9e59acb14eda 100644 --- a/lib/matplotlib/backend_managers.pyi +++ b/lib/matplotlib/backend_managers.pyi @@ -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]: ... diff --git a/lib/matplotlib/cm.pyi b/lib/matplotlib/cm.pyi index 5a90863dec41..be8f10b39cb6 100644 --- a/lib/matplotlib/cm.pyi +++ b/lib/matplotlib/cm.pyi @@ -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 diff --git a/lib/matplotlib/collections.pyi b/lib/matplotlib/collections.pyi index 92cac6aa513e..01682a55b374 100644 --- a/lib/matplotlib/collections.pyi +++ b/lib/matplotlib/collections.pyi @@ -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): @@ -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__( diff --git a/lib/matplotlib/colorbar.pyi b/lib/matplotlib/colorbar.pyi index f623697acae4..f71c5759fc55 100644 --- a/lib/matplotlib/colorbar.pyi +++ b/lib/matplotlib/colorbar.pyi @@ -123,7 +123,7 @@ def make_axes( shrink: float = ..., aspect: float = ..., **kwargs -): ... +) -> tuple[Axes, dict[str, Any]]: ... def make_axes_gridspec( parent: Axes, *, @@ -133,4 +133,4 @@ def make_axes_gridspec( shrink: float = ..., aspect: float = ..., **kwargs -): ... +) -> tuple[Axes, dict[str, Any]]: ... diff --git a/lib/matplotlib/dviread.pyi b/lib/matplotlib/dviread.pyi index 5a2f7a0de62a..bf5cfcbe317a 100644 --- a/lib/matplotlib/dviread.pyi +++ b/lib/matplotlib/dviread.pyi @@ -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 diff --git a/lib/matplotlib/gridspec.pyi b/lib/matplotlib/gridspec.pyi index ea441bcef216..6e2273080b3b 100644 --- a/lib/matplotlib/gridspec.pyi +++ b/lib/matplotlib/gridspec.pyi @@ -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: ... diff --git a/lib/matplotlib/image.pyi b/lib/matplotlib/image.pyi index 43a9c1cf9628..d39490457eae 100644 --- a/lib/matplotlib/image.pyi +++ b/lib/matplotlib/image.pyi @@ -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: ... diff --git a/lib/matplotlib/mathtext.pyi b/lib/matplotlib/mathtext.pyi index 15ceb74a2dda..706f83a6b168 100644 --- a/lib/matplotlib/mathtext.pyi +++ b/lib/matplotlib/mathtext.pyi @@ -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, @@ -30,4 +25,4 @@ def math_to_image( format: str | None = ..., *, color: ColorType | None = ... -): ... +) -> float: ... diff --git a/lib/matplotlib/mlab.pyi b/lib/matplotlib/mlab.pyi index d93a7a3a5187..1f23288dd10b 100644 --- a/lib/matplotlib/mlab.pyi +++ b/lib/matplotlib/mlab.pyi @@ -13,7 +13,7 @@ def detrend( | Callable[[ArrayLike, int | None], ArrayLike] | None = ..., axis: int | None = ..., -): ... +) -> ArrayLike: ... def detrend_mean(x: ArrayLike, axis: int | None = ...) -> ArrayLike: ... def detrend_none(x: ArrayLike, axis: int | None = ...) -> ArrayLike: ... def detrend_linear(y: ArrayLike) -> ArrayLike: ... @@ -54,29 +54,26 @@ def specgram( x: ArrayLike, NFFT: int | None = ..., Fs: float | None = ..., - detrend: Literal["none", "mean", "linear"] - | Callable[[ArrayLike, int | None], ArrayLike] - | None = ..., + detrend: Literal["none", "mean", "linear"] | Callable[[ArrayLike, int | None], ArrayLike] | None = ..., window: Callable[[ArrayLike], ArrayLike] | ArrayLike | None = ..., noverlap: int | None = ..., pad_to: int | None = ..., sides: Literal["default", "onesided", "twosided"] | None = ..., scale_by_freq: bool | None = ..., mode: Literal["psd", "complex", "magnitude", "angle", "phase"] | None = ..., -): ... +) -> tuple[ArrayLike, ArrayLike, ArrayLike]: ... def cohere( x: ArrayLike, y: ArrayLike, NFFT: int = ..., Fs: float = ..., - detrend: Literal["none", "mean", "linear"] - | Callable[[ArrayLike, int | None], ArrayLike] = ..., + detrend: Literal["none", "mean", "linear"] | Callable[[ArrayLike, int | None], ArrayLike] = ..., window: Callable[[ArrayLike], ArrayLike] | ArrayLike = ..., noverlap: int = ..., pad_to: int | None = ..., sides: Literal["default", "onesided", "twosided"] = ..., scale_by_freq: bool | None = ..., -): ... +) -> tuple[ArrayLike, ArrayLike]: ... class GaussianKDE: dataset: ArrayLike diff --git a/lib/matplotlib/patches.pyi b/lib/matplotlib/patches.pyi index e1b07f8874ec..29fe36aa6c6b 100644 --- a/lib/matplotlib/patches.pyi +++ b/lib/matplotlib/patches.pyi @@ -28,7 +28,7 @@ class Patch(artist.Artist): **kwargs, ) -> None: ... def get_verts(self) -> ArrayLike: ... - def contains(self, mouseevent: MouseEvent, radius: float | None = None): ... + def contains(self, mouseevent: MouseEvent, radius: float | None = None) -> tuple[bool, dict[Any, Any]]: ... def contains_point( self, point: tuple[float, float], radius: float | None = ... ) -> bool: ... @@ -287,7 +287,7 @@ class Circle(Ellipse): self, xy: tuple[float, float], radius: float = ..., **kwargs ) -> None: ... def set_radius(self, radius: float) -> None: ... - def get_radius(self): ... + def get_radius(self) -> float: ... radius = property(get_radius, set_radius) class Arc(Ellipse): @@ -663,7 +663,7 @@ class FancyBboxPatch(Patch): mutation_aspect: float = ..., **kwargs, ) -> None: ... - def set_boxstyle(self, boxstyle: str | BoxStyle | None = ..., **kwargs): ... + def set_boxstyle(self, boxstyle: str | BoxStyle | None = ..., **kwargs) -> None: ... def get_boxstyle(self) -> BoxStyle: ... def set_mutation_scale(self, scale: float) -> None: ... def get_mutation_scale(self) -> float: ... @@ -711,11 +711,9 @@ class FancyArrowPatch(Patch): ) -> None: ... def set_patchA(self, patchA: Patch) -> None: ... def set_patchB(self, patchB: Patch) -> None: ... - def set_connectionstyle( - self, connectionstyle: str | ConnectionStyle | None = ..., **kwargs - ): ... + def set_connectionstyle(self, connectionstyle: str | ConnectionStyle | None = ..., **kwargs) -> None: ... def get_connectionstyle(self) -> ConnectionStyle: ... - def set_arrowstyle(self, arrowstyle: str | ArrowStyle | None = ..., **kwargs): ... + def set_arrowstyle(self, arrowstyle: str | ArrowStyle | None = ..., **kwargs) -> None: ... def get_arrowstyle(self) -> ArrowStyle: ... def set_mutation_scale(self, scale: float) -> None: ... def get_mutation_scale(self) -> float: ... diff --git a/lib/matplotlib/path.pyi b/lib/matplotlib/path.pyi index 0aac50e8479f..c96c5a0ba9e4 100644 --- a/lib/matplotlib/path.pyi +++ b/lib/matplotlib/path.pyi @@ -44,7 +44,7 @@ class Path: @property def readonly(self) -> bool: ... def copy(self) -> Path: ... - def __deepcopy__(self, memo: dict[int, Any] | None = ...): ... + def __deepcopy__(self, memo: dict[int, Any] | None = ...) -> Path: ... deepcopy = __deepcopy__ @classmethod diff --git a/lib/matplotlib/patheffects.pyi b/lib/matplotlib/patheffects.pyi index 3f632413e37d..5d8dcfeab61a 100644 --- a/lib/matplotlib/patheffects.pyi +++ b/lib/matplotlib/patheffects.pyi @@ -1,9 +1,11 @@ +from collections.abc import Iterable, Sequence +from typing import Any + from matplotlib.backend_bases import RendererBase, GraphicsContextBase from matplotlib.path import Path from matplotlib.patches import Patch from matplotlib.transforms import Transform -from collections.abc import Iterable, Sequence from matplotlib.typing import ColorType class AbstractPathEffect: @@ -21,7 +23,7 @@ class PathEffectRenderer(RendererBase): def __init__( self, path_effects: Iterable[AbstractPathEffect], renderer: RendererBase ) -> None: ... - def copy_with_path_effect(self, path_effects: Iterable[AbstractPathEffect]): ... + def copy_with_path_effect(self, path_effects: Iterable[AbstractPathEffect]) -> PathEffectRenderer: ... def draw_path( self, gc: GraphicsContextBase, @@ -46,7 +48,7 @@ class PathEffectRenderer(RendererBase): *args, **kwargs ) -> None: ... - def __getattribute__(self, name: str): ... + def __getattribute__(self, name: str) -> Any: ... class Normal(AbstractPathEffect): ... diff --git a/lib/matplotlib/projections/polar.pyi b/lib/matplotlib/projections/polar.pyi index 9dd0def6a803..2592d4947184 100644 --- a/lib/matplotlib/projections/polar.pyi +++ b/lib/matplotlib/projections/polar.pyi @@ -139,9 +139,7 @@ class PolarAxes(Axes): @overload def set_thetalim(self, minval: float, maxval: float, /) -> tuple[float, float]: ... @overload - def set_thetalim( - self, *, thetamin: float, thetamax: float - ) -> tuple[float, float]: ... + def set_thetalim(self, *, thetamin: float, thetamax: float) -> tuple[float, float]: ... def set_theta_offset(self, offset: float) -> None: ... def get_theta_offset(self) -> float: ... def set_theta_zero_location( @@ -169,7 +167,7 @@ class PolarAxes(Axes): emit: bool = ..., auto: bool = ..., **kwargs, - ): ... + ) -> tuple[float, float]: ... def get_rlabel_position(self) -> float: ... def set_rlabel_position(self, value: float) -> None: ... def set_rscale(self, *args, **kwargs) -> None: ... diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index d575a921eace..7722a48ba8fb 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -39,7 +39,7 @@ from __future__ import annotations -from contextlib import ExitStack +from contextlib import AbstractContextManager, ExitStack from enum import Enum import functools import importlib @@ -379,7 +379,7 @@ def new_figure_manager(num, *args, FigureClass=Figure, **kwargs): fig = FigureClass(*args, **kwargs) return new_figure_manager_given_figure(num, fig) - def draw_if_interactive(): + def draw_if_interactive() -> None: if matplotlib.is_interactive(): manager = _pylab_helpers.Gcf.get_active() if manager: @@ -666,7 +666,7 @@ def rc(group: str, **kwargs) -> None: def rc_context( rc: dict[str, Any] | None = None, fname: str | pathlib.Path | os.PathLike | None = None, -): +) -> AbstractContextManager[None]: return matplotlib.rc_context(rc, fname) @@ -4107,7 +4107,7 @@ def yscale(value: str | ScaleBase, **kwargs) -> None: # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def autumn(): +def autumn() -> None: """ Set the colormap to 'autumn'. @@ -4118,7 +4118,7 @@ def autumn(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def bone(): +def bone() -> None: """ Set the colormap to 'bone'. @@ -4129,7 +4129,7 @@ def bone(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def cool(): +def cool() -> None: """ Set the colormap to 'cool'. @@ -4140,7 +4140,7 @@ def cool(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def copper(): +def copper() -> None: """ Set the colormap to 'copper'. @@ -4151,7 +4151,7 @@ def copper(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def flag(): +def flag() -> None: """ Set the colormap to 'flag'. @@ -4162,7 +4162,7 @@ def flag(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def gray(): +def gray() -> None: """ Set the colormap to 'gray'. @@ -4173,7 +4173,7 @@ def gray(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def hot(): +def hot() -> None: """ Set the colormap to 'hot'. @@ -4184,7 +4184,7 @@ def hot(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def hsv(): +def hsv() -> None: """ Set the colormap to 'hsv'. @@ -4195,7 +4195,7 @@ def hsv(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def jet(): +def jet() -> None: """ Set the colormap to 'jet'. @@ -4206,7 +4206,7 @@ def jet(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def pink(): +def pink() -> None: """ Set the colormap to 'pink'. @@ -4217,7 +4217,7 @@ def pink(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def prism(): +def prism() -> None: """ Set the colormap to 'prism'. @@ -4228,7 +4228,7 @@ def prism(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def spring(): +def spring() -> None: """ Set the colormap to 'spring'. @@ -4239,7 +4239,7 @@ def spring(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def summer(): +def summer() -> None: """ Set the colormap to 'summer'. @@ -4250,7 +4250,7 @@ def summer(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def winter(): +def winter() -> None: """ Set the colormap to 'winter'. @@ -4261,7 +4261,7 @@ def winter(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def magma(): +def magma() -> None: """ Set the colormap to 'magma'. @@ -4272,7 +4272,7 @@ def magma(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def inferno(): +def inferno() -> None: """ Set the colormap to 'inferno'. @@ -4283,7 +4283,7 @@ def inferno(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def plasma(): +def plasma() -> None: """ Set the colormap to 'plasma'. @@ -4294,7 +4294,7 @@ def plasma(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def viridis(): +def viridis() -> None: """ Set the colormap to 'viridis'. @@ -4305,7 +4305,7 @@ def viridis(): # Autogenerated by boilerplate.py. Do not edit as changes will be lost. -def nipy_spectral(): +def nipy_spectral() -> None: """ Set the colormap to 'nipy_spectral'. diff --git a/lib/matplotlib/sankey.pyi b/lib/matplotlib/sankey.pyi index c5199bc3add8..4a40c31e3c6a 100644 --- a/lib/matplotlib/sankey.pyi +++ b/lib/matplotlib/sankey.pyi @@ -56,5 +56,6 @@ class Sankey: connect: tuple[int, int] = ..., rotation: float = ..., **kwargs - ): ... + # Replace return with Self when py3.9 is dropped + ) -> Sankey: ... def finish(self) -> list[Any]: ... diff --git a/lib/matplotlib/scale.pyi b/lib/matplotlib/scale.pyi index e29394e9316a..7fec8e68cc5a 100644 --- a/lib/matplotlib/scale.pyi +++ b/lib/matplotlib/scale.pyi @@ -174,5 +174,5 @@ class LogitScale(ScaleBase): def get_transform(self) -> LogitTransform: ... def get_scale_names() -> list[str]: ... -def scale_factory(scale: str, axis: Axis, **kwargs): ... +def scale_factory(scale: str, axis: Axis, **kwargs) -> ScaleBase: ... def register_scale(scale_class: type[ScaleBase]) -> None: ... diff --git a/lib/matplotlib/spines.pyi b/lib/matplotlib/spines.pyi index 30e113830a28..0a5243776730 100644 --- a/lib/matplotlib/spines.pyi +++ b/lib/matplotlib/spines.pyi @@ -1,13 +1,13 @@ +from collections.abc import Callable, Iterator, MutableMapping +from typing import Any, Literal, TypeVar, overload + import matplotlib.patches as mpatches -from collections.abc import MutableMapping, Iterator from matplotlib.axes import Axes from matplotlib.axis import Axis from matplotlib.path import Path from matplotlib.transforms import Transform from matplotlib.typing import ColorType -from typing import Literal, TypeVar, overload - class Spine(mpatches.Patch): axes: Axes spine_type: str @@ -63,7 +63,7 @@ class Spine(mpatches.Patch): class SpinesProxy: def __init__(self, spine_dict: dict[str, Spine]) -> None: ... - def __getattr__(self, name: str): ... + def __getattr__(self, name: str) -> Callable[..., None]: ... def __dir__(self) -> list[str]: ... class Spines(MutableMapping[str, Spine]): diff --git a/lib/matplotlib/table.pyi b/lib/matplotlib/table.pyi index dab049153811..842c55edb5a3 100644 --- a/lib/matplotlib/table.pyi +++ b/lib/matplotlib/table.pyi @@ -52,14 +52,14 @@ class Table(Artist): ) -> None: ... def add_cell(self, row: int, col: int, *args, **kwargs) -> Cell: ... def __setitem__(self, position: tuple[int, int], cell: Cell) -> None: ... - def __getitem__(self, position: tuple[int, int]): ... + def __getitem__(self, position: tuple[int, int]) -> Cell: ... @property def edges(self) -> str | None: ... @edges.setter def edges(self, value: str | None) -> None: ... def draw(self, renderer) -> None: ... def get_children(self) -> list[Artist]: ... - def get_window_extent(self, renderer: RendererBase | None = ...): ... + def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ... def auto_set_column_width(self, col: int | Sequence[int]) -> None: ... def auto_set_font_size(self, value: bool = ...) -> None: ... def scale(self, xscale: float, yscale: float) -> None: ... diff --git a/lib/matplotlib/text.pyi b/lib/matplotlib/text.pyi index 62878f30b4f2..6a83b1bbbed9 100644 --- a/lib/matplotlib/text.pyi +++ b/lib/matplotlib/text.pyi @@ -103,9 +103,9 @@ class Text(Artist): def get_usetex(self) -> bool: ... def set_parse_math(self, parse_math: bool) -> None: ... def get_parse_math(self) -> bool: ... - def set_fontname(self, fontname: str | Iterable[str]): ... + def set_fontname(self, fontname: str | Iterable[str]) -> None: ... def get_antialiased(self) -> bool: ... - def set_antialiased(self, antialiased: bool): ... + def set_antialiased(self, antialiased: bool) -> None: ... class OffsetFrom: def __init__( diff --git a/lib/matplotlib/ticker.pyi b/lib/matplotlib/ticker.pyi index 20c75ce33f74..2ef1c9f53f1d 100644 --- a/lib/matplotlib/ticker.pyi +++ b/lib/matplotlib/ticker.pyi @@ -25,9 +25,9 @@ class TickHelper: class Formatter(TickHelper): locs: list[float] def __call__(self, x: float, pos: int | None = ...) -> str: ... - def format_ticks(self, values: list[float]): ... - def format_data(self, value: float): ... - def format_data_short(self, value: float): ... + def format_ticks(self, values: list[float]) -> list[str]: ... + def format_data(self, value: float) -> str: ... + def format_data_short(self, value: float) -> str: ... def get_offset(self) -> str: ... def set_locs(self, locs: list[float]) -> None: ... @staticmethod @@ -86,8 +86,8 @@ class ScalarFormatter(Formatter): def useMathText(self, val: bool | None) -> None: ... def set_scientific(self, b: bool) -> None: ... def set_powerlimits(self, lims: tuple[int, int]) -> None: ... - def format_data_short(self, value: float | np.ma.MaskedArray): ... - def format_data(self, value: float): ... + def format_data_short(self, value: float | np.ma.MaskedArray) -> str: ... + def format_data(self, value: float) -> str: ... class LogFormatter(Formatter): minor_thresholds: tuple[float, float] diff --git a/lib/matplotlib/transforms.pyi b/lib/matplotlib/transforms.pyi index 11b7f49319ea..68e55612b7f1 100644 --- a/lib/matplotlib/transforms.pyi +++ b/lib/matplotlib/transforms.pyi @@ -20,7 +20,7 @@ class TransformNode: def __init__(self, shorthand_name: str | None = ...) -> None: ... def __copy__(self) -> TransformNode: ... def invalidate(self) -> None: ... - def set_children(self, *children: TransformNode): ... + def set_children(self, *children: TransformNode) -> None: ... def frozen(self) -> TransformNode: ... class BboxBase(TransformNode): @@ -80,7 +80,7 @@ class BboxBase(TransformNode): # anchored type can be s/str/Literal["C", "SW", "S", "SE", "E", "NE", "N", "NW", "W"] def anchored( self, c: tuple[float, float] | str, container: BboxBase | None = ... - ): ... + ) -> Bbox: ... def shrunk(self, mx: float, my: float) -> Bbox: ... def shrunk_to_aspect( self, @@ -224,10 +224,10 @@ class AffineBase(Transform): class Affine2DBase(AffineBase): input_dims: Literal[2] output_dims: Literal[2] - def frozen(self): ... + def frozen(self) -> Affine2D: ... @property def is_separable(self): ... - def to_values(self): ... + def to_values(self) -> tuple[float, float, float, float, float, float]: ... class Affine2D(Affine2DBase): def __init__(self, matrix: ArrayLike | None = ..., **kwargs) -> None: ... @@ -326,12 +326,12 @@ def nonsingular( tiny: float = ..., increasing: bool = ..., ) -> tuple[float, float]: ... -def interval_contains(interval: tuple[float, float], val: float): ... -def interval_contains_open(interval: tuple[float, float], val: float): ... +def interval_contains(interval: tuple[float, float], val: float) -> bool: ... +def interval_contains_open(interval: tuple[float, float], val: float) -> bool: ... def offset_copy( trans: Transform, fig: Figure | None = ..., x: float = ..., y: float = ..., units: Literal["inches", "points", "dots"] = ..., -): ... +) -> Transform: ... diff --git a/lib/matplotlib/tri/_triangulation.pyi b/lib/matplotlib/tri/_triangulation.pyi index ce9264106f27..6e00b272eda9 100644 --- a/lib/matplotlib/tri/_triangulation.pyi +++ b/lib/matplotlib/tri/_triangulation.pyi @@ -18,7 +18,7 @@ class Triangulation: triangles: ArrayLike | None = ..., mask: ArrayLike | None = ..., ) -> None: ... - def calculate_plane_coefficients(self, z: ArrayLike): ... + def calculate_plane_coefficients(self, z: ArrayLike) -> np.ndarray: ... @property def edges(self) -> np.ndarray: ... def get_cpp_triangulation(self) -> _tri.Triangulation: ... diff --git a/lib/matplotlib/tri/_tripcolor.pyi b/lib/matplotlib/tri/_tripcolor.pyi index 5d7f8e9a88a6..42acffcdc52e 100644 --- a/lib/matplotlib/tri/_tripcolor.pyi +++ b/lib/matplotlib/tri/_tripcolor.pyi @@ -1,4 +1,5 @@ from matplotlib.axes import Axes +from matplotlib.collections import PolyCollection, TriMesh from matplotlib.colors import Normalize, Colormap from matplotlib.tri._triangulation import Triangulation @@ -17,10 +18,10 @@ def tripcolor( cmap: str | Colormap | None = ..., vmin: float | None = ..., vmax: float | None = ..., - shading: Literal["flat", "gouraud"] = ..., + shading: Literal["flat"] = ..., facecolors: ArrayLike | None = ..., **kwargs -): ... +) -> PolyCollection: ... @overload def tripcolor( ax: Axes, @@ -33,7 +34,38 @@ def tripcolor( cmap: str | Colormap | None = ..., vmin: float | None = ..., vmax: float | None = ..., - shading: Literal["flat", "gouraud"] = ..., + shading: Literal["flat"] = ..., facecolors: ArrayLike | None = ..., **kwargs -): ... +) -> PolyCollection: ... +@overload +def tripcolor( + ax: Axes, + triangulation: Triangulation, + c: ArrayLike = ..., + *, + alpha: float = ..., + norm: str | Normalize | None = ..., + cmap: str | Colormap | None = ..., + vmin: float | None = ..., + vmax: float | None = ..., + shading: Literal["gouraud"], + facecolors: ArrayLike | None = ..., + **kwargs +) -> TriMesh: ... +@overload +def tripcolor( + ax: Axes, + x: ArrayLike, + y: ArrayLike, + c: ArrayLike = ..., + *, + alpha: float = ..., + norm: str | Normalize | None = ..., + cmap: str | Colormap | None = ..., + vmin: float | None = ..., + vmax: float | None = ..., + shading: Literal["gouraud"], + facecolors: ArrayLike | None = ..., + **kwargs +) -> TriMesh: ... diff --git a/lib/matplotlib/widgets.pyi b/lib/matplotlib/widgets.pyi index c90d7cd002e1..8af25957e9d1 100644 --- a/lib/matplotlib/widgets.pyi +++ b/lib/matplotlib/widgets.pyi @@ -52,7 +52,7 @@ class Button(AxesWidget): *, useblit: bool = ... ) -> None: ... - def on_clicked(self, func: Callable[[Event], Any]): ... + def on_clicked(self, func: Callable[[Event], Any]) -> int: ... def disconnect(self, cid: int) -> None: ... class SliderBase(AxesWidget): diff --git a/tools/boilerplate.py b/tools/boilerplate.py index bcb41bc20600..a0943df00866 100644 --- a/tools/boilerplate.py +++ b/tools/boilerplate.py @@ -83,7 +83,7 @@ def {name}{signature}: """ CMAP_TEMPLATE = ''' -def {name}(): +def {name}() -> None: """ Set the colormap to {name!r}. From 532d92566d7e0a1e83741e8fb0a3caf026049f90 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 4 Aug 2023 20:16:30 -0400 Subject: [PATCH 2/3] Canonicalize Text.set_fontname --- lib/matplotlib/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index d4922fc51774..4ea4cc1a1485 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1350,7 +1350,7 @@ def get_parse_math(self): def set_fontname(self, fontname): """ - Alias for `set_family`. + Alias for `set_fontfamily`. One-way alias only: the getter differs. @@ -1364,7 +1364,7 @@ def set_fontname(self, fontname): .font_manager.FontProperties.set_family """ - return self.set_family(fontname) + self.set_fontfamily(fontname) class OffsetFrom: From 371f41df62e9d5f98568c5a40af4aa8ea55a8b68 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 4 Aug 2023 20:18:53 -0400 Subject: [PATCH 3/3] Tighten return type of Axes.bar_label Also, tweak tests to use canonical (and thus typed) getters. --- lib/matplotlib/axes/_axes.py | 4 +- lib/matplotlib/axes/_axes.pyi | 2 +- lib/matplotlib/pyplot.py | 2 +- lib/matplotlib/tests/test_axes.py | 68 +++++++++++++++---------------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 934c5677ac13..036d4f284fe5 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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: diff --git a/lib/matplotlib/axes/_axes.pyi b/lib/matplotlib/axes/_axes.pyi index 2d223fc49cd0..bdd29684925d 100644 --- a/lib/matplotlib/axes/_axes.pyi +++ b/lib/matplotlib/axes/_axes.pyi @@ -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]], diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 7722a48ba8fb..ef8e54a98cae 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2728,7 +2728,7 @@ def bar_label( label_type: Literal["center", "edge"] = "edge", padding: float = 0, **kwargs, -) -> list[Text]: +) -> list[Annotation]: return gca().bar_label( container, labels=labels, diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 6c970cdbeb3c..ac9dd0787a43 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8154,11 +8154,11 @@ def test_bar_label_location_vertical(): rects = ax.bar(xs, heights) labels = ax.bar_label(rects) assert labels[0].xy == (xs[0], heights[0]) - assert labels[0].get_ha() == 'center' - assert labels[0].get_va() == 'bottom' + assert labels[0].get_horizontalalignment() == 'center' + assert labels[0].get_verticalalignment() == 'bottom' assert labels[1].xy == (xs[1], heights[1]) - assert labels[1].get_ha() == 'center' - assert labels[1].get_va() == 'top' + assert labels[1].get_horizontalalignment() == 'center' + assert labels[1].get_verticalalignment() == 'top' def test_bar_label_location_vertical_yinverted(): @@ -8168,11 +8168,11 @@ def test_bar_label_location_vertical_yinverted(): rects = ax.bar(xs, heights) labels = ax.bar_label(rects) assert labels[0].xy == (xs[0], heights[0]) - assert labels[0].get_ha() == 'center' - assert labels[0].get_va() == 'top' + assert labels[0].get_horizontalalignment() == 'center' + assert labels[0].get_verticalalignment() == 'top' assert labels[1].xy == (xs[1], heights[1]) - assert labels[1].get_ha() == 'center' - assert labels[1].get_va() == 'bottom' + assert labels[1].get_horizontalalignment() == 'center' + assert labels[1].get_verticalalignment() == 'bottom' def test_bar_label_location_horizontal(): @@ -8181,11 +8181,11 @@ def test_bar_label_location_horizontal(): rects = ax.barh(ys, widths) labels = ax.bar_label(rects) assert labels[0].xy == (widths[0], ys[0]) - assert labels[0].get_ha() == 'left' - assert labels[0].get_va() == 'center' + assert labels[0].get_horizontalalignment() == 'left' + assert labels[0].get_verticalalignment() == 'center' assert labels[1].xy == (widths[1], ys[1]) - assert labels[1].get_ha() == 'right' - assert labels[1].get_va() == 'center' + assert labels[1].get_horizontalalignment() == 'right' + assert labels[1].get_verticalalignment() == 'center' def test_bar_label_location_horizontal_yinverted(): @@ -8195,11 +8195,11 @@ def test_bar_label_location_horizontal_yinverted(): rects = ax.barh(ys, widths) labels = ax.bar_label(rects) assert labels[0].xy == (widths[0], ys[0]) - assert labels[0].get_ha() == 'left' - assert labels[0].get_va() == 'center' + assert labels[0].get_horizontalalignment() == 'left' + assert labels[0].get_verticalalignment() == 'center' assert labels[1].xy == (widths[1], ys[1]) - assert labels[1].get_ha() == 'right' - assert labels[1].get_va() == 'center' + assert labels[1].get_horizontalalignment() == 'right' + assert labels[1].get_verticalalignment() == 'center' def test_bar_label_location_horizontal_xinverted(): @@ -8209,11 +8209,11 @@ def test_bar_label_location_horizontal_xinverted(): rects = ax.barh(ys, widths) labels = ax.bar_label(rects) assert labels[0].xy == (widths[0], ys[0]) - assert labels[0].get_ha() == 'right' - assert labels[0].get_va() == 'center' + assert labels[0].get_horizontalalignment() == 'right' + assert labels[0].get_verticalalignment() == 'center' assert labels[1].xy == (widths[1], ys[1]) - assert labels[1].get_ha() == 'left' - assert labels[1].get_va() == 'center' + assert labels[1].get_horizontalalignment() == 'left' + assert labels[1].get_verticalalignment() == 'center' def test_bar_label_location_horizontal_xyinverted(): @@ -8224,11 +8224,11 @@ def test_bar_label_location_horizontal_xyinverted(): rects = ax.barh(ys, widths) labels = ax.bar_label(rects) assert labels[0].xy == (widths[0], ys[0]) - assert labels[0].get_ha() == 'right' - assert labels[0].get_va() == 'center' + assert labels[0].get_horizontalalignment() == 'right' + assert labels[0].get_verticalalignment() == 'center' assert labels[1].xy == (widths[1], ys[1]) - assert labels[1].get_ha() == 'left' - assert labels[1].get_va() == 'center' + assert labels[1].get_horizontalalignment() == 'left' + assert labels[1].get_verticalalignment() == 'center' def test_bar_label_location_center(): @@ -8237,11 +8237,11 @@ def test_bar_label_location_center(): rects = ax.barh(ys, widths) labels = ax.bar_label(rects, label_type='center') assert labels[0].xy == (0.5, 0.5) - assert labels[0].get_ha() == 'center' - assert labels[0].get_va() == 'center' + assert labels[0].get_horizontalalignment() == 'center' + assert labels[0].get_verticalalignment() == 'center' assert labels[1].xy == (0.5, 0.5) - assert labels[1].get_ha() == 'center' - assert labels[1].get_va() == 'center' + assert labels[1].get_horizontalalignment() == 'center' + assert labels[1].get_verticalalignment() == 'center' @image_comparison(['test_centered_bar_label_nonlinear.svg']) @@ -8273,11 +8273,11 @@ def test_bar_label_location_errorbars(): rects = ax.bar(xs, heights, yerr=1) labels = ax.bar_label(rects) assert labels[0].xy == (xs[0], heights[0] + 1) - assert labels[0].get_ha() == 'center' - assert labels[0].get_va() == 'bottom' + assert labels[0].get_horizontalalignment() == 'center' + assert labels[0].get_verticalalignment() == 'bottom' assert labels[1].xy == (xs[1], heights[1] - 1) - assert labels[1].get_ha() == 'center' - assert labels[1].get_va() == 'top' + assert labels[1].get_horizontalalignment() == 'center' + assert labels[1].get_verticalalignment() == 'top' @pytest.mark.parametrize('fmt', [ @@ -8312,7 +8312,7 @@ def test_bar_label_nan_ydata(): labels = ax.bar_label(bars) assert [l.get_text() for l in labels] == ['', '1'] assert labels[0].xy == (2, 0) - assert labels[0].get_va() == 'bottom' + assert labels[0].get_verticalalignment() == 'bottom' def test_bar_label_nan_ydata_inverted(): @@ -8322,7 +8322,7 @@ def test_bar_label_nan_ydata_inverted(): labels = ax.bar_label(bars) assert [l.get_text() for l in labels] == ['', '1'] assert labels[0].xy == (2, 0) - assert labels[0].get_va() == 'bottom' + assert labels[0].get_verticalalignment() == 'bottom' def test_nan_barlabels():