Skip to content

Commit 9c4c9a9

Browse files
timhoffmmeeseeksmachine
authored andcommitted
Backport PR matplotlib#31920: Fix various small type hint issues
1 parent f4461ce commit 9c4c9a9

12 files changed

Lines changed: 66 additions & 31 deletions

File tree

ci/mypy-stubtest-allowlist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ matplotlib\.backends\..*
33
matplotlib\.tests(\..*)?
44
matplotlib\.pylab(\..*)?
55
matplotlib\._.*
6-
matplotlib\.rcsetup\._listify_validator
76
matplotlib\.rcsetup\._validate_linestyle
87
matplotlib\.ft2font\.Glyph
98
matplotlib\.ft2font\.LayoutItem

lib/matplotlib/artist.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ _T_Artist = TypeVar("_T_Artist", bound=Artist)
2323
def allow_rasterization(draw): ...
2424

2525
class _XYPair(NamedTuple):
26-
x: ArrayLike
27-
y: ArrayLike
26+
x: list[float]
27+
y: list[float]
2828

2929
class Artist:
3030
zorder: float

lib/matplotlib/axes/_base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class _AxesBase(martist.Artist):
6767

6868
def __init__(
6969
self,
70-
fig: Figure,
70+
fig: Figure | SubFigure,
7171
*args: tuple[float, float, float, float] | Bbox | int,
7272
facecolor: ColorType | None = ...,
7373
frameon: bool = ...,

lib/matplotlib/backends/registry.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BackendRegistry:
2525
def backend_for_gui_framework(self, framework: str) -> str | None: ...
2626
def is_valid_backend(self, backend: str) -> bool: ...
2727
def list_all(self) -> list[str]: ...
28-
def list_builtin(self, filter_: BackendFilter | None) -> list[str]: ...
28+
def list_builtin(self, filter_: BackendFilter | None = ...) -> list[str]: ...
2929
def list_gui_frameworks(self) -> list[str]: ...
3030
def load_backend_module(self, backend: str) -> ModuleType: ...
3131
def resolve_backend(self, backend: str | None) -> tuple[str, str | None]: ...

lib/matplotlib/colorbar.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ from collections.abc import Sequence
1313
from typing import Any, Literal, overload
1414
from .typing import ColorType
1515

16-
class _ColorbarSpine(mspines.Spines):
16+
17+
class _ColorbarSpine(mspines.Spine):
1718
def __init__(self, axes: Axes): ...
18-
def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox:...
19+
def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ...
1920
def set_xy(self, xy: ArrayLike) -> None: ...
20-
def draw(self, renderer: RendererBase | None) -> None:...
21+
def draw(self, renderer: RendererBase | None) -> None: ...
2122

2223

2324
class Colorbar:

lib/matplotlib/font_manager.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class FontManager:
147147
rebuild_if_missing: bool = ...,
148148
) -> list[FontPath]: ...
149149

150-
def is_opentype_cff_font(filename: str) -> bool: ...
150+
def is_opentype_cff_font(filename: str | os.PathLike) -> bool: ...
151151
def get_font(
152152
font_filepaths: Iterable[str | bytes | os.PathLike | FontPath] | str | bytes | os.PathLike | FontPath,
153153
) -> ft2font.FT2Font: ...

lib/matplotlib/image.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class _ImageBase(colorizer.ColorizingArtist):
8484
self, renderer: RendererBase, magnification: float = ..., unsampled: bool = ...
8585
) -> tuple[np.ndarray, float, float, Affine2D]: ...
8686
def draw(self, renderer: RendererBase) -> None: ...
87-
def write_png(self, fname: str | pathlib.Path | BinaryIO) -> None: ...
87+
def write_png(self, fname: str | os.PathLike | BinaryIO) -> None: ...
8888
def set_data(self, A: ArrayLike | None) -> None: ...
8989
def set_array(self, A: ArrayLike | None) -> None: ...
9090
def get_shape(self) -> tuple[int, int, int]: ...

lib/matplotlib/rcsetup.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ from matplotlib.typing import ColorType, LineStyleType, MarkEveryType
77

88
_T = TypeVar("_T")
99

10-
def _listify_validator(s: Callable[[Any], _T]) -> Callable[[Any], list[_T]]: ...
10+
def _listify_validator(
11+
scalar_validator: Callable[[Any], _T],
12+
allow_stringlist: bool = ...,
13+
*,
14+
n: int | None = ...,
15+
doc: str | None = ...,
16+
) -> Callable[[Any], list[_T]]: ...
1117

1218
class ValidateInStrings:
1319
key: str

lib/matplotlib/testing/compare.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from collections.abc import Callable
2+
from os import PathLike
23
from typing import Literal, overload
34

45
from numpy.typing import NDArray
56

67
__all__ = ["calculate_rms", "comparable_formats", "compare_images"]
78

8-
def make_test_filename(fname: str, purpose: str) -> str: ...
9+
def make_test_filename(fname: str | PathLike, purpose: str) -> str: ...
910
def get_cache_dir() -> str: ...
1011
def get_file_hash(path: str, block_size: int = ...) -> str: ...
1112

1213
converter: dict[str, Callable[[str, str], None]] = {}
1314

1415
def comparable_formats() -> list[str]: ...
15-
def convert(filename: str, cache: bool) -> str: ...
16+
def convert(filename: str | PathLike, cache: bool) -> str: ...
1617
def crop_to_same(
1718
actual_path: str, actual_image: NDArray, expected_path: str, expected_image: NDArray
1819
) -> tuple[NDArray, NDArray]: ...

lib/matplotlib/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def invalidate(self):
156156
Invalidate this `TransformNode` and triggers an invalidation of its
157157
ancestors. Should be called any time the transform changes.
158158
"""
159-
return self._invalidate_internal(
159+
self._invalidate_internal(
160160
level=self._INVALID_AFFINE_ONLY if self.is_affine else self._INVALID_FULL,
161161
invalidating_node=self)
162162

0 commit comments

Comments
 (0)