Repository navigation
fix: treat basedpyright warnings as errors and clear the backlog - #792
Merged
MaximilianSoerenPollak merged 1 commit intoSep 2, 2026
Conversation
basedpyright exits 0 when a run reports only warnings, so the
pre-commit hook passed even though the repository had accumulated 29
warnings. Set `failOnWarnings` so any warning fails the run.
The rules stay configured as "warning" on purpose: they should still
render as warnings in the IDE rather than as hard errors. Only the CLI
exit code changes, which is what gates pre-commit.
Fix the warnings this uncovered:
- Annotate the Sphinx event handlers `annotate_testcase_results` and
`use_document_source_as_plantuml_cwd`, whose untyped `doctree`
parameter also made every downstream import partially unknown.
- Narrow decoded JSON/TOML with the `cast("dict[str, object]", ...)`
idiom already used in `src/tests/docs_bzl/helpers.py`, in the
cross-module compatibility reporter and the module verification
report tool.
- Annotate `monkeypatch` parameters as `pytest.MonkeyPatch`.
- Mark the deliberate white-box imports of private helpers in tests
with `pyright: ignore[reportPrivateUsage]`.
Also restrict the hook to Python sources and its own configuration.
It checks the whole project and is slow, so there is no reason to run
it for a docs-only or workflow-only commit.
Signed-off-by: SebStefenel <stefenel.sebastian@gmail.com>
SebStefenel
requested review from
AlexanderLanin,
MaximilianSoerenPollak,
a-zw,
dcalavrezo-qorix and
nradakovic
as code owners
September 1, 2026 20:26
AlexanderLanin
requested changes
Sep 2, 2026
AlexanderLanin
left a comment
Member
There was a problem hiding this comment.
Thanks for this contribution! Please have a look at some comments I made.
| - name: Setup venv | ||
| run: bazel run --lockfile_mode=error //:ide_support | ||
|
|
||
| # The pre-commit hook only protects contributors who installed it. |
Member
There was a problem hiding this comment.
we already run pre-commit via on-pr.yml
Contributor
Author
There was a problem hiding this comment.
Sorry I missed that. Dropped that commit.
| ) | ||
|
|
||
| assert warning_rules, "expected some diagnostic rules to be set to 'warning'" | ||
| assert settings.get("failOnWarnings") is True, ( |
Member
There was a problem hiding this comment.
testing a config file doesnt seem reasonable, as this simply duplicates the config flag into this test and now both places set/compare it to true.
Contributor
Author
There was a problem hiding this comment.
Yeah fair, removed.
Contributor
|
Documentation preview for this pull request is available at: |
SebStefenel
force-pushed
the
fix/753-basedpyright-warnings
branch
from
September 2, 2026 07:01
e22a65d to
1307514
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📌 Description
Fixes #753.
Root cause
basedpyrightexits0when a run reports only warnings. Every rule in[tool.pyright]is deliberately configured as"warning", so the pre-commithook invoked the checker, saw a non-empty warning list, and still passed. That
is how 29 warnings accumulated on
main.Setting
failOnWarnings = truemakes any warning produce a non-zero exit code.The rules stay declared as
"warning"on purpose — they should still render aswarnings in the IDE rather than as hard errors. Only the CLI exit code changes,
which is exactly what gates pre-commit and CI.
Warning fixes (29 → 0)
All of them were fixed by adding annotations or narrowing types. No rule was
relaxed or disabled, and no
# type: ignorewas used to paper over a realtyping problem.
annotate_testcase_resultsanduse_document_source_as_plantuml_cwdhad an untypeddoctreeparameter.This was the highest-leverage fix: an untyped handler also made its imports
partially unknown in other modules, so three warnings collapsed into one
annotation.
cast("dict[str, object]", ...)idiom already established in
src/tests/docs_bzl/helpers.py, applied in thecross-module compatibility reporter and the module verification report tool.
monkeypatchparameters — annotated aspytest.MonkeyPatch, matchingthe existing convention in
score_source_code_linker/tests.marked
# pyright: ignore[reportPrivateUsage] - white-box unit test, thesame form already used in
src/incremental_dirty_build_test.py.Hook scope
BasedPyrightalways checks the whole project, so it does not take filenames.It previously ran on every commit, including docs-only and workflow-only
ones. A
files:filter now limits this slow hook to Python sources and its ownconfiguration.
🚨 Impact Analysis
No runtime behaviour changes. The production changes are type annotations and
cast(...)calls, which are erased at runtime, plus one control-flow rewritein
_flatten_needs/_link_idsthat was verified to be behaviour-preserving(see below). The remaining changes are tooling configuration.
✅ Checklist
— no user-facing documentation needed changing:
docs/does not describethe pre-commit or type-checking setup, and the README's pre-commit
section covers installation only, which is unaffected. The why is
documented as comments at both changed configuration sites, since the
non-obvious part is why warnings must fail the CLI while remaining
warnings in the IDE.
— no new tests. Nothing changed at runtime: the edits are type
annotations and
cast(...)calls, which are erased at runtime. The onecontrol-flow rewrite is differential-tested against the original logic
(below) and covered by the existing suite. Enforcement comes from
failOnWarningsitself, which the pre-commit run in CI already exercises.Verification
Verified against a real Bazel-provisioned venv
(
bazel run //:ide_support, basedpyright 1.39.10, Python 3.12.12) — not anapproximation:
basedpyrightresultmain(before)0 errors, 29 warnings0← the bug0 errors, 0 warnings00 errors, 2 warnings1← gate worksThe middle row is the point: on
mainthe checker reported 29 warnings andstill exited
0, so the pre-commit hook passed.Also:
ruff checkandruff format --check→ clean.pytest src/extensions tools→ 283 passed, 2 failed. Both failuresreproduce identically on unmodified
main(verified by checking it out) andare unrelated to this PR; one of them additionally needs
bazelonPATH,which it has in CI.
_flatten_needs,_link_idsandCompatibilityReporter.from_manifestwere differential-tested against theoriginal logic across edge cases (non-dict entries, non-
strmount_at,malformed JSON, missing keys, non-list values) — identical output, including
error messages.