Skip to content

BLD: Install the type stub for backends.registry - #32481

Merged
ksunden merged 1 commit into
matplotlib:mainfrom
maaz7409:bld-install-registry-stub
Oct 16, 2026
Merged

ksunden merged 1 commit into
matplotlib:mainfrom
maaz7409:bld-install-registry-stub

Conversation

@maaz7409

Copy link
Copy Markdown
Contributor

PR summary

lib/matplotlib/backends/registry.pyi was added in 3.9 (#27719) but is not
listed in typing_sources in lib/matplotlib/backends/meson.build, so it
has never been installed. Wheels from 3.9.0 to 3.11.2 ship registry.py
without it.

Because py.typed is installed, type checkers read the unannotated
registry.py instead. They still know that backend_registry is a
BackendRegistry, but all its methods are untyped. With mypy on an
installed wheel:

from matplotlib.backends.registry import BackendFilter, backend_registry

reveal_type(backend_registry.list_builtin(BackendFilter.INTERACTIVE))
# before: Any    after: list[str]
reveal_type(backend_registry.resolve_gui_or_backend("qt"))
# before: Any    after: tuple[str, str | None]

Under mypy --strict, each of these calls is currently a
no-untyped-call error.

This PR adds the file to the list. A wheel built with the change has
registry.pyi as its only new file, and stubtest reports no differences
between the stub and the runtime module. I ran it without the allowlist,
because ci/mypy-stubtest-allowlist.txt skips everything under
matplotlib.backends.

The two other uninstalled stubs are left out on purpose:

  • a) backends/backend_pdf.pyi has annotation errors that would reject valid
    code once installed, e.g. PdfPages.savefig(fig, dpi=300). I'll fix and
    install it in a follow-up PR.
  • b) dates.pyi covers only the module's functions, so installing it would make
    from matplotlib.dates import DateFormatter a type error. It can be added
    once the stub is complete (Add type hints for matplotlib.dates module #30126).

AI Disclosure

Claude Code (Claude Opus 5.5 (high) ) flagged this while making a core audit. This change was also verified by Codex ( GPT-6.1 sol (xhigh) ).

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • [N/A] New and changed code is tested (install list only; checked by building a wheel)
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

@QuLogic QuLogic added this to the v3.11.3 milestone Oct 16, 2026
@ksunden
ksunden merged commit 6c628b9 into matplotlib:main Oct 16, 2026
46 checks passed
iccir added a commit that referenced this pull request Oct 16, 2026
…481-on-v3.11.x

Backport PR #32481 on branch v3.11.x (BLD: Install the type stub for backends.registry)
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.

3 participants