Skip to content

🎨 style: give every Final annotation its type - #3375

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:style/final-type-args
Oct 2, 2026
Merged

gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:style/final-type-args

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

52 Final annotations in src/, tests/, tasks/ and hatch_build.py carried no type, so the checker inferred each one. This gives every one its type.

Change Where
Final[<type>] at each site 15 files
TypedDicts for the GitHub, npm and pins JSON tasks/upgrade_ci_tools.py
CycloneDX TypedDicts replace dict[str, Any], shared with the zipapp SBOM, cast removed hatch_build.py, tasks/zipapp_sbom.py
one-use plugin lookup inlined tests/unit/test_conftest.py

The SBOMs built from this branch match those from main byte for byte, apart from the recorded hashes of the two edited files and the serial number derived from them. tasks/validate_sbom.py accepts the new zipapp SBOM. The one Any left is hatchling's own initialize(build_data: dict[str, Any]) hook signature.

Bare Final left the checker to infer each value's type. Spell out the
type at every site, and model the JSON that tasks/upgrade_ci_tools.py
reads with TypedDicts instead of untyped values. Inline the one-use
plugin lookup in tests/unit/test_conftest.py.
hatch_build.py built its SBOM parts as dict[str, Any], so
tasks/zipapp_sbom.py had to cast them and could not type the document
it assembles. Describe the CycloneDX parts as TypedDicts in
hatch_build.py, reuse them in zipapp_sbom.py, drop the cast, and type
the zipapp document's Final values. Apart from the hashes of the two
edited files and the serial derived from them, the generated SBOMs
match the previous output byte for byte.
@gaborbernat
gaborbernat merged commit 5183a10 into pypa:main Oct 2, 2026
144 of 146 checks passed
@gaborbernat
gaborbernat deleted the style/final-type-args branch October 3, 2026 15:12
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.

1 participant