Skip to content

Add explicit overloads for pyplot.{show,subplot} #30202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ def draw_if_interactive(*args, **kwargs):
return _get_backend_mod().draw_if_interactive(*args, **kwargs)


@overload
def show(*, block: bool, **kwargs) -> None: ...


@overload
def show(*args: Any, **kwargs: Any) -> None: ...


# This function's signature is rewritten upon backend-load by switch_backend.
def show(*args, **kwargs) -> None:
"""
Expand Down Expand Up @@ -1393,6 +1401,18 @@ def cla() -> None:

## More ways of creating Axes ##

@overload
def subplot(nrows: int, ncols: int, index: int, /, **kwargs): ...


@overload
def subplot(pos: int | SubplotSpec, /, **kwargs): ...


@overload
def subplot(**kwargs): ...


@_docstring.interpd
def subplot(*args, **kwargs) -> Axes:
"""
Expand All @@ -1406,7 +1426,6 @@ def subplot(*args, **kwargs) -> Axes:
subplot(nrows, ncols, index, **kwargs)
subplot(pos, **kwargs)
subplot(**kwargs)
subplot(ax)

Parameters
----------
Expand Down