Fix return type of pyplot.subplot_tool / NavigationToolbar2.configure_subplots by karlhillx · Pull Request #31996 · matplotlib/matplotlib · GitHub
Skip to content

Fix return type of pyplot.subplot_tool / NavigationToolbar2.configure_subplots#31996

Closed
karlhillx wants to merge 1 commit into
matplotlib:mainfrom
karlhillx:fix-subplot-tool-return-type
Closed

Fix return type of pyplot.subplot_tool / NavigationToolbar2.configure_subplots#31996
karlhillx wants to merge 1 commit into
matplotlib:mainfrom
karlhillx:fix-subplot-tool-return-type

Conversation

@karlhillx

@karlhillx karlhillx commented Jul 4, 2026

Copy link
Copy Markdown

Widen the return annotation of pyplot.subplot_tool and NavigationToolbar2.configure_subplots from SubplotTool | None to Any. The Qt backends return a QDialog and the toolmanager branch already returns None, so the annotations were misleading. Direction per timhoffm on #31979. Docstring updated to describe the backend-dependent return value.

Also drop the now-unused TYPE_CHECKING import of SubplotTool, and alphabetize the typing import.

Closes #31979

Copilot AI review requested due to automatic review settings July 4, 2026 21:24
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Matplotlib’s public typing and documentation around pyplot.subplot_tool() / NavigationToolbar2.configure_subplots() to match real backend behavior (widgets returns SubplotTool, Qt returns a Qt dialog, toolmanager returns None), without changing runtime behavior.

Changes:

  • Widen pyplot.subplot_tool() return annotation to Any and update its docstring to describe the backend-dependent return value.
  • Widen the stubbed return type of NavigationToolbar2.configure_subplots() to Any in backend_bases.pyi.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/matplotlib/pyplot.py Updates subplot_tool() return type annotation and expands the docstring to document backend-dependent return values.
lib/matplotlib/backend_bases.pyi Updates the public stub signature of NavigationToolbar2.configure_subplots() to return Any.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/matplotlib/pyplot.py Outdated
Comment thread lib/matplotlib/pyplot.py
…re_subplots to Any

Per timhoffm on matplotlib#31979. The Qt backends return QDialog subclasses and
the toolmanager branch already returns None, so the prior annotation
was misleading. Update docstring to describe the backend-dependent
return value. Also drop the now-unused TYPE_CHECKING import of
SubplotTool and alphabetize the typing import.

Closes matplotlib#31979
@karlhillx karlhillx force-pushed the fix-subplot-tool-return-type branch from 71587ed to ed03cea Compare July 4, 2026 21:45
@karlhillx

Copy link
Copy Markdown
Author

@karlhillx karlhillx closed this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: pyplot.subplot_tool doesn't always return a SubplotTool

2 participants