Skip to content

build-lectures: report Python warnings in cell outputs, as warning-outputs beside error-outputs #330

Open

Description

@mmcky

Why

A lecture that prints a DeprecationWarning or FutureWarning builds green today, and the warning sits in the published page until the library removes the feature and the lecture breaks. Nothing in QuantEcon's builds reports it by class:

  • build-lectures' error-outputs check finds error outputs, not warnings.
  • -W covers Sphinx's and myst-nb's warnings. myst-nb's execute.stderr_output: warn (nb_output_stderr) does turn any stderr output into a mystnb.stderr warning, cached pages included. But it names no warning class and fires on any stderr, and no lecture repository sets it.

QuantEcon/action-check-warnings was written for this, and is to be archived: it has no workflow consumer, and was last pushed on 2025-10-01. Its open issues record what went wrong with it:

The need is still there. This issue proposes meeting it in build-lectures, where the outputs already are.

How warnings appear in a notebook

Checked with nbclient 0.11, ipykernel 6.31 and IPython 9.15:

  • every warning that reaches the output is a stream output on stderr, as a <file>:<line>: <Class>: <message> line, even one raised inside _repr_html_, and never display_data;
  • these never reach it: a DeprecationWarning attributed to library code (IPython shows it only for __main__), any PendingDeprecationWarning (hidden by the default filters), repeats from the same line, anything after warnings.filterwarnings('ignore'), and a thread's warning after its cell ends;
  • a warning turned into an error becomes an error output, which error-outputs already finds;
  • nb_output_stderr acts only when the page is rendered: the notebook myst-nb writes, and the cache, keep stderr. So under remove, remove-warn or a cell's remove-stderr tag, the page hides a warning this check would still see.

Proposal

New inputs on build-lectures, with a passthrough on build-jupyter-cache as error-outputs has:

Input Values Default
warning-outputs ignore, warn or fail ignore at first, so that no build changes on release
warning-patterns warning class names to report, one per line, matched as a substring of the class DeprecationWarning, FutureWarning, Pandas4Warning

Matching by substring catches subclasses such as MatplotlibDeprecationWarning (the real case in QuantEcon/lecture-python.myst#587). Pandas4Warning is listed because pandas 3's deprecation subclass doesn't contain the base name.

How it works:

  • It reads the notebooks build-lectures already reads for error-outputs in _build/jupyter_execute, not the HTML, so it doesn't depend on the theme. Like error-outputs, it depends on myst-nb's jupyter_execute and jupyter-cache, so Jupyter Book 2 (MAINT: check-warnings should be reviewed when JB2 is released meta#200) would need it rewritten.
  • It checks only notebooks with a source under source-dir, which keeps removed lectures out. Fixtures stay out because it reads only the book being built.
  • Each match gets an annotation on the source file at the cell's line, and the step summary lists all of them, since annotations are capped at 10 per step. A warning-output-count output gives the total.
  • It opens no issue: the step summary and annotations are the report.

Which pages it reads decides where it's useful. Reading the execution cache's copy of cached pages, as #326 (still open, for #322) does for errors, would report every page on every pull request over a restored cache, which is QuantEcon/meta#224's complaint. Reading only the notebooks the build executed reports just the pages whose code changed on a pull request, and every page in cache.yml's weekly build from scratch. So the proposal is the second: in the templates, ci.yml sets warn (the warnings a pull request's own changed pages print), and cache.yml sets warn for a whole-book weekly report through build-jupyter-cache. fail in publish.yml would block a release over an upstream deprecation, so the templates don't use it.

Open questions

  • The first release's default: ignore, or warn? warn changes no build's result, but adds annotations to consumers' runs.
  • The opt-out for a warning a lecture prints on purpose: reuse the existing remove-stderr cell tag (the page hides it, so the check skips it too), or a separate tag that keeps the warning visible but unreported?
  • Should cells whose stderr the page removes (nb_output_stderr: remove or remove-warn) be skipped, or reported with a note that readers don't see them?

Claude Code (on behalf of mmcky)

Activity

  1. added
    enhancement
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions