From d809a1213c4f3d60df1c4f3ddc8058dff0d2fd51 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Jun 2023 22:07:35 -0400 Subject: [PATCH] Avoid deprecated typing hints These were all deprecated in Python 3.9 by PEP 585 and Generic Alias types (i.e., stuff like `typing.List` -> `list`). --- lib/matplotlib/_path.pyi | 4 +++- lib/matplotlib/cbook.pyi | 3 +-- lib/matplotlib/pyplot.py | 10 ++++------ lib/matplotlib/typing.py | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/_path.pyi b/lib/matplotlib/_path.pyi index 5656375953da..456905528b28 100644 --- a/lib/matplotlib/_path.pyi +++ b/lib/matplotlib/_path.pyi @@ -1,5 +1,7 @@ -from typing import Sequence +from collections.abc import Sequence + import numpy as np + from .transforms import BboxBase def affine_transform(points: np.ndarray, trans: np.ndarray) -> np.ndarray: ... diff --git a/lib/matplotlib/cbook.pyi b/lib/matplotlib/cbook.pyi index f4ed66145375..69e52a05680c 100644 --- a/lib/matplotlib/cbook.pyi +++ b/lib/matplotlib/cbook.pyi @@ -11,7 +11,6 @@ from numpy.typing import ArrayLike from typing import ( Any, - ContextManager, Generic, IO, Literal, @@ -68,7 +67,7 @@ def open_file_cm( path_or_file: str | os.PathLike | IO, mode: str = ..., encoding: str | None = ..., -) -> ContextManager[IO]: ... +) -> contextlib.AbstractContextManager[IO]: ... def is_scalar_or_string(val: Any) -> bool: ... @overload def get_sample_data( diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 026be7ae90cf..6110c95eada7 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -81,16 +81,14 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: + from collections.abc import Callable, Hashable, Iterable, Sequence import datetime import pathlib import os + from typing import Any, BinaryIO, Literal import PIL - from numpy.typing import ArrayLike - from typing import ( - Any, BinaryIO, Callable, Hashable, Literal, Sequence, Iterable, Type - ) from matplotlib.axis import Tick from matplotlib.axes._base import _AxesBase @@ -229,7 +227,7 @@ def set_loglevel(*args, **kwargs) -> None: @_copy_docstring_and_deprecators(Artist.findobj) def findobj( o: Artist | None = None, - match: Callable[[Artist], bool] | Type[Artist] | None = None, + match: Callable[[Artist], bool] | type[Artist] | None = None, include_self: bool = True ) -> list[Artist]: if o is None: @@ -751,7 +749,7 @@ def figure( # defaults to rc figure.edgecolor edgecolor: ColorType | None = None, frameon: bool = True, - FigureClass: Type[Figure] = Figure, + FigureClass: type[Figure] = Figure, clear: bool = False, **kwargs ) -> Figure: diff --git a/lib/matplotlib/typing.py b/lib/matplotlib/typing.py index dffff8996573..9605504ded90 100644 --- a/lib/matplotlib/typing.py +++ b/lib/matplotlib/typing.py @@ -9,9 +9,9 @@ The ``typing`` module and type stub files are considered provisional and may change at any time without a deprecation period. """ -from collections.abc import Sequence +from collections.abc import Hashable, Sequence import pathlib -from typing import Any, Hashable, Literal, Union +from typing import Any, Literal, Union from . import path from ._enums import JoinStyle, CapStyle