From 95b7dc3184f90263383001b8c786ed0f7561321b Mon Sep 17 00:00:00 2001 From: Dor Harpaz Date: Thu, 19 Nov 2026 13:37:19 +0200 Subject: [PATCH] forbid deprecation warnings in saved notebook outputs Co-Authored-By: Claude Opus 5.5 --- .../notebook_forbid_deprecation_outputs.py | 32 +++++++++++++++++++ .pre-commit-config.yaml | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 .internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py diff --git a/.internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py b/.internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py new file mode 100755 index 000000000..27b75b8b5 --- /dev/null +++ b/.internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import re + +from _common import iter_cells, load_notebook, report, run_precommit + +# Also matches subclasses, e.g. `ClassiqDeprecationWarning` and `PendingDeprecationWarning` +DEPRECATION_WARNING = re.compile(r"\w*(DeprecationWarning|FutureWarning|SyntaxWarning)") + + +def forbid_deprecation_outputs(notebook_path: str) -> bool: + nb = load_notebook(notebook_path) + + result = True + for cell_idx, cell in iter_cells(nb, "code"): + for output in cell.get("outputs", []): + if output.get("output_type") != "stream": + continue + if match := DEPRECATION_WARNING.search(output.get("text", "")): + result = False + report( + notebook_path, + "deprecation warning in the outputs - replace the deprecated call, and re-run the notebook", + cell_idx, + match.string[match.start() :].splitlines()[0], + ) + + return result + + +if __name__ == "__main__": + run_precommit(forbid_deprecation_outputs) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1055fa6fc..f4594a7ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -111,6 +111,38 @@ repos: additional_dependencies: - "nbformat" require_serial: true + - id: forbid-deprecation-outputs + name: forbid deprecation warnings in outputs + entry: .internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py + language: python + files: \.ipynb$ + # These notebooks' outputs still show a deprecation warning. + # Remove each one once it's fixed and re-run. + exclude: | + (?x)(^|/)( + projected_based_embedding_tutorial| + link_monitoring| + portfolio_optimization| + task_scheduling_problem| + integer_linear_programming| + evidence_scaling_labs| + max_clique| + max_k_vertex_cover| + set_partition| + ising_model| + radio_access_network_positioning_antennas| + benchmark_dynamical_localization| + benchmark_ghz| + advection_equation_2nd_place_submission| + advection_equation_winning_submission| + select_structures_BE| + quantum_walks_via_efficient_blockencoding| + stateprep_guassian_using_qsvt| + modular_exp_example + )\.ipynb$ + additional_dependencies: + - "nbformat" + require_serial: true - id: validate-latex name: validate notebook LaTeX