fix(about): make about.py metadata lookup type-checker-proof - #122
Merged
Merged
Conversation
woutervh
force-pushed
the
fix/ty-0.0.29-about
branch
from
August 30, 2026 14:36
fbd41a8 to
d2f7a5c
Compare
Dependabot #103 (bump `ty` 0.0.19 -> 0.0.29) turns the Linting job red on every Python version. `ty` rejects two constructs in `about.py` that older `ty` accepted and that `# type: ignore[...]` does not silence: - `msg.json` -> `unresolved-attribute` (typeshed resolves `importlib.metadata.metadata()` as `email.message.Message`). - `version: str = pkginfo.get("version", "unknown")` -> `invalid-assignment` (the value is `str | list[str]`). Materialise the distribution metadata into a plain `dict[str, str]` via `{key: msg[key] for key in msg}` - only `__iter__` (over keys) and `__getitem__` are guaranteed on `PackageMetadata` across 3.9-3.14, unlike `.json` / `.get` - then read `Author-email` / `License(-Expression)` / `Version` off the dict. Fallback branches keep their `# pragma: no cover`. Verified against `ty` 0.0.75 locally (plus ruff, pylint 10/10, mypy on 3.10/3.11/3.14, pre-commit, pytest+coverage 100%). Merging unblocks #103, which then only carries the lockfile bump.
woutervh
force-pushed
the
fix/ty-0.0.29-about
branch
from
August 30, 2026 14:37
d2f7a5c to
3619fd8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #122 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 2 2
Lines 24 24
=========================================
Hits 24 24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Why
Dependabot #103 (bump
ty0.0.19 -> 0.0.29) turns the Linting job red onevery Python version.
ty checkrejects two constructs insrc/autoadd_bindir/about.pythat oldertyaccepted and that# type: ignore[...]comments do not silence:unresolved-attribute-msg.json(typeshed resolvesimportlib.metadata.metadata()asemail.message.Message, which has no.json).invalid-assignment-version: str = pkginfo.get("version", "unknown")(the value is
str | list[str]).What
Materialise the distribution metadata into a plain
dict[str, str]with{key: msg[key] for key in msg}- only__iter__(over keys) and__getitem__are guaranteed on
importlib.metadata.PackageMetadataacross 3.9-3.14, unlike.jsonor.get(mypy 1.19 rejects.geton 3.10/3.11). Then readAuthor-email/License(-Expression)/Versionoff the dict. Fallbackbranches keep their
# pragma: no cover.Single-file change;
uv.lockis untouched here.Verification (local)
Against
ty0.0.75 (newer than #103's 0.0.29):just ruff-check,just pylint(10/10),just mypy(explicitly on 3.10 / 3.11 / 3.14),just ty-check,pre-commit run --all-files, andjust pytest-coverage(100%, 7 passed) all pass.
Follow-up
Merging this unblocks #103; that PR then only carries the
tylockfile bump.