Skip to content

Commit 4b03f0c

Browse files
Add explicit overloads for pyplot.{show,subplot} (#30202)
* Create show overloads on pyplot.py (cherry picked from commit 1ff2bd2) * Create subplot overloads on pyplot.py (cherry picked from commit f4693e3) * Removed subplot(Axes) on overloads and docstring * Update show overloads * Correct mypy error * Add typing to overloaded copy of show * Revert superfluous changes --------- Co-authored-by: Corenthin ZOZOR <corenthin.zozor@gmail.com>
1 parent c78c2f4 commit 4b03f0c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/matplotlib/pyplot.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,14 @@ def draw_if_interactive(*args, **kwargs):
569569
return _get_backend_mod().draw_if_interactive(*args, **kwargs)
570570

571571

572+
@overload
573+
def show(*, block: bool, **kwargs) -> None: ...
574+
575+
576+
@overload
577+
def show(*args: Any, **kwargs: Any) -> None: ...
578+
579+
572580
# This function's signature is rewritten upon backend-load by switch_backend.
573581
def show(*args, **kwargs) -> None:
574582
"""
@@ -1393,6 +1401,18 @@ def cla() -> None:
13931401

13941402
## More ways of creating Axes ##
13951403

1404+
@overload
1405+
def subplot(nrows: int, ncols: int, index: int, /, **kwargs): ...
1406+
1407+
1408+
@overload
1409+
def subplot(pos: int | SubplotSpec, /, **kwargs): ...
1410+
1411+
1412+
@overload
1413+
def subplot(**kwargs): ...
1414+
1415+
13961416
@_docstring.interpd
13971417
def subplot(*args, **kwargs) -> Axes:
13981418
"""
@@ -1406,7 +1426,6 @@ def subplot(*args, **kwargs) -> Axes:
14061426
subplot(nrows, ncols, index, **kwargs)
14071427
subplot(pos, **kwargs)
14081428
subplot(**kwargs)
1409-
subplot(ax)
14101429
14111430
Parameters
14121431
----------

0 commit comments

Comments
 (0)