Skip to content

Commit 4242506

Browse files
committed
Avoid union for dynamic type hints
1 parent c7a128e commit 4242506

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/matplotlib/figure.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = ...,

lib/matplotlib/pyplot.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,18 +1564,18 @@ def subplot(*args, **kwargs) -> Axes:
15641564

15651565
@overload
15661566
def subplots(
1567-
nrows: int = ...,
1568-
ncols: int = ...,
1567+
nrows: Literal[1] = ...,
1568+
ncols: Literal[1] = ...,
15691569
*,
15701570
sharex: bool | Literal["none", "all", "row", "col"] = ...,
15711571
sharey: bool | Literal["none", "all", "row", "col"] = ...,
1572-
squeeze: Literal[True],
1572+
squeeze: Literal[True] = ...,
15731573
width_ratios: Sequence[float] | None = ...,
15741574
height_ratios: Sequence[float] | None = ...,
15751575
subplot_kw: dict[str, Any] | None = ...,
15761576
gridspec_kw: dict[str, Any] | None = ...,
15771577
**fig_kw
1578-
) -> tuple[Figure, Any]:
1578+
) -> tuple[Figure, Axes]:
15791579
...
15801580

15811581

@@ -1596,6 +1596,23 @@ def subplots(
15961596
...
15971597

15981598

1599+
@overload
1600+
def subplots(
1601+
nrows: int = ...,
1602+
ncols: int = ...,
1603+
*,
1604+
sharex: bool | Literal["none", "all", "row", "col"] = ...,
1605+
sharey: bool | Literal["none", "all", "row", "col"] = ...,
1606+
squeeze: bool = ...,
1607+
width_ratios: Sequence[float] | None = ...,
1608+
height_ratios: Sequence[float] | None = ...,
1609+
subplot_kw: dict[str, Any] | None = ...,
1610+
gridspec_kw: dict[str, Any] | None = ...,
1611+
**fig_kw
1612+
) -> tuple[Figure, Any]:
1613+
...
1614+
1615+
15991616
def subplots(
16001617
nrows: int = 1, ncols: int = 1, *,
16011618
sharex: bool | Literal["none", "all", "row", "col"] = False,

0 commit comments

Comments
 (0)