Skip to content

Fix bench_diskless type checking with mypy 2 - #1501

Merged
jswhit merged 1 commit into
Unidata:masterfrom
glaziermag:fix/bench-diskless-mypy
Sep 28, 2026
Merged

jswhit merged 1 commit into
Unidata:masterfrom
glaziermag:fix/bench-diskless-mypy

Conversation

@glaziermag

Copy link
Copy Markdown
Contributor

Mypy 2 rejects the format annotation in the diskless-read benchmark because the earlier loop already defines that name. Rename the second variable to fmt and update its three uses, retaining the Literal["NETCDF3_CLASSIC"] annotation required by write_netcdf.

Fixes #1498.

Validation:

  • Reproduced both reported errors on current master with mypy 2.3.1.
  • With the fix, mypy --no-incremental examples passes all 14 files and mypy --no-incremental test passes all 57 files using the repository's type stubs on Python 3.14.
  • The full netcdf-c master build and test workflow passed on this exact commit (52a6a411), including Stubtest.

…no-redef)

`for format in [...]` at line 43 defines `format` as str; the later annotated
assignment `format: Literal[\"NETCDF3_CLASSIC\"] = ...` is a re-annotation that
mypy >= 2.0.0 rejects ([no-redef]), and the lost annotation then makes the
`write_netcdf(format=format)` call fail [arg-type]. This keeps the Literal
annotation the call needs but gives the second variable its own name.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jswhit
jswhit merged commit 046dea0 into Unidata:master Sep 28, 2026
42 of 44 checks passed
@jswhit

jswhit commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

thanks for this fix!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build_master red on every push since 2026-07-12: mypy 2.0 rejects the re-annotated format in examples/bench_diskless.py:56

3 participants