🎨 style: give every Final annotation its type - #3375
Merged
Merged
Conversation
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.
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.
52
Finalannotations insrc/,tests/,tasks/andhatch_build.pycarried no type, so the checker inferred each one. This gives every one its type.Final[<type>]at each sitetasks/upgrade_ci_tools.pydict[str, Any], shared with the zipapp SBOM,castremovedhatch_build.py,tasks/zipapp_sbom.pytests/unit/test_conftest.pyThe SBOMs built from this branch match those from
mainbyte for byte, apart from the recorded hashes of the two edited files and the serial number derived from them.tasks/validate_sbom.pyaccepts the new zipapp SBOM. The oneAnyleft is hatchling's owninitialize(build_data: dict[str, Any])hook signature.