GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TYP,BLD: Fix backend_pdf stub errors and install it by maaz7409 · Pull Request #32586 · matplotlib/matplotlib

Conversation

@maaz7409

@maaz7409 maaz7409 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

PR summary

This PR is follow-up to #32481, which installed registry.pyi and left
backend_pdf.pyi out because its errors would reject valid code.
It fixes those errors and adds backend_pdf.pyi to typing_sources.

Fixes
Valid code rejected by the stub Fix
pdf.savefig(fig, dpi=300) **kwargs: dict[str, Any] → **kwargs: Any
fig.savefig(pdf), plt.savefig(pdf) accept PdfPages as fname, as the Figure.savefig docstring says
PdfPages(f, metadata={"CreationDate": None}) (documented) and PdfPages(f, metadata=md) with md: dict[str, str] type metadata as Mapping[str, str | datetime | Name | None]; infodict() still returns a dict
gc.paint(fill_rule=...), Op.paint_path(..., fill_rule=...) add fill_rule (from #32253)
Op.paint_path(...).pdfRepr() return type bytes → Op, as at runtime
Op.fill_evenodd, Op.fill_evenodd_stroke add the members (from #32253)
from matplotlib.backends.backend_pdf import FigureManagerPdf add the alias

I checked with mypy and stubtest (16 → 1 mypy errors on valid usage, 23 → 18 stubtest differences, none from the changed items)

Also tests : ruff, CI's mypy run, test_backend_pdf.py and test_pyplot_up_to_date pass.

AI Disclosure

Claude Code ( Claude Opus 5.5 (high) ) assisted me in writing the fix.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • [N/A] New and changed code is tested (stub-only change)
  • [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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@maaz7409
TYP: Fix errors in the backend_pdf stub
f705350
@github-actions github-actions Bot added topic: pyplot API topic: figures and subfigures labels Nov 9, 2026
timhoffm
timhoffm reviewed Nov 9, 2026
View reviewed changes
Comment thread lib/matplotlib/figure.pyi Outdated
def savefig(
self,
fname: str | os.PathLike | IO,
fname: str | os.PathLike | IO | PdfPages,

@timhoffm timhoffm Nov 9, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's more complicated than that. fname is passed on to self.canvas.print_figure, and FigureCanvasBase.print_figure does not accept PdfPages either. Mypy doesn't flag this only because, with figure.pyi present, the implementation of Figure.savefig is never type-checked against the stubs.

The type system can't reasonably express the current situation, where the types savefig accepts depend on the runtime type of another object (figure.canvas). Adding PdfPages to FigureCanvasBase.print_figure would mean adding it to all canvas subclasses as well: too permissive, cumbersome, and ultimately impractical for third-party backends.

T.b.h. I just wouldn't bother with the type imperfection.

The backend_pdf.pyi changes themselves seem ok.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@maaz7409 maaz7409 Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ok, so do i drop both commits : fname changes to this figure.pyi as well as pyplot.py ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

timhoffm reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@maaz7409
BLD: Install the type stub for backends.backend_pdf
0fa049d
@maaz7409
maaz7409 force-pushed the typ-fix-install-backend-pdf-stub branch from b19f8ec to 0fa049d Compare November 10, 2026 10:08
@github-actions github-actions Bot removed topic: pyplot API topic: figures and subfigures labels Nov 10, 2026
timhoffm
timhoffm approved these changes Nov 10, 2026
View reviewed changes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@timhoffm timhoffm timhoffm approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@maaz7409 @timhoffm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.