Skip to content

Commit 9fa7b31

Browse files
committed
[TYP] Fix overloads of FigureBase.subplots
1 parent 9cd2812 commit 9fa7b31

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

lib/matplotlib/figure.pyi

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from collections.abc import Callable, Hashable, Iterable
22
import os
3-
from typing import Any, IO, Literal, TypeVar, overload
3+
from typing import Any, IO, Literal, Sequence, TypeVar, overload
44

55
import numpy as np
66
from numpy.typing import ArrayLike
77

88
from matplotlib.artist import Artist
9-
from matplotlib.axes import Axes, SubplotBase
9+
from matplotlib.axes import Axes
1010
from matplotlib.backend_bases import (
1111
FigureCanvasBase,
1212
MouseButton,
@@ -92,6 +92,20 @@ class FigureBase(Artist):
9292
@overload
9393
def add_subplot(self, **kwargs) -> Axes: ...
9494
@overload
95+
def subplots(
96+
self,
97+
nrows: Literal[1] = ...,
98+
ncols: Literal[1] = ...,
99+
*,
100+
sharex: bool | Literal["none", "all", "row", "col"] = ...,
101+
sharey: bool | Literal["none", "all", "row", "col"] = ...,
102+
squeeze: Literal[True] = ...,
103+
width_ratios: Sequence[float] | None = ...,
104+
height_ratios: Sequence[float] | None = ...,
105+
subplot_kw: dict[str, Any] | None = ...,
106+
gridspec_kw: dict[str, Any] | None = ...,
107+
) -> Axes: ...
108+
@overload
95109
def subplots(
96110
self,
97111
nrows: int = ...,
@@ -100,11 +114,11 @@ class FigureBase(Artist):
100114
sharex: bool | Literal["none", "all", "row", "col"] = ...,
101115
sharey: bool | Literal["none", "all", "row", "col"] = ...,
102116
squeeze: Literal[False],
103-
width_ratios: ArrayLike | None = ...,
104-
height_ratios: ArrayLike | None = ...,
117+
width_ratios: Sequence[float] | None = ...,
118+
height_ratios: Sequence[float] | None = ...,
105119
subplot_kw: dict[str, Any] | None = ...,
106-
gridspec_kw: dict[str, Any] | None = ...
107-
) -> np.ndarray: ...
120+
gridspec_kw: dict[str, Any] | None = ...,
121+
) -> np.ndarray: ... # TODO numpy/numpy#24738
108122
@overload
109123
def subplots(
110124
self,
@@ -114,11 +128,11 @@ class FigureBase(Artist):
114128
sharex: bool | Literal["none", "all", "row", "col"] = ...,
115129
sharey: bool | Literal["none", "all", "row", "col"] = ...,
116130
squeeze: bool = ...,
117-
width_ratios: ArrayLike | None = ...,
118-
height_ratios: ArrayLike | None = ...,
131+
width_ratios: Sequence[float] | None = ...,
132+
height_ratios: Sequence[float] | None = ...,
119133
subplot_kw: dict[str, Any] | None = ...,
120-
gridspec_kw: dict[str, Any] | None = ...
121-
) -> np.ndarray | SubplotBase | Axes: ...
134+
gridspec_kw: dict[str, Any] | None = ...,
135+
) -> Axes | np.ndarray: ...
122136
def delaxes(self, ax: Axes) -> None: ...
123137
def clear(self, keep_observers: bool = ...) -> None: ...
124138
def clf(self, keep_observers: bool = ...) -> None: ...

0 commit comments

Comments
 (0)