Check type issues with ty and fix problems it finds#100
Merged
Conversation
Adds ty to the dev dependency group and clears every diagnostic it surfaces against the `us` package: - Drop unused `# type: ignore` directives on jellyfish and pytest. - Restructure `lookup()` so `fallback_key` is only ever bound to a `str`, removing the false `None | str` dict-key write. - Guard `state.shapefile_urls()` against `None` in the CLI and in the skipped network test before iterating. - Narrow `state.fips` with an assert in `test_county_fips_prefixed_by_state`. - Suppress the `requests` import inside the permanently-skipped `test_head` with `# ty: ignore[unresolved-import]`. Closes APR-33. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
Review notes:
|
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.
Summary
Adds Astral's
tyto the dev dependency group and clears every diagnostic it surfaced against theuspackage. After this changeuv run ty check usreportsAll checks passed!(down from 8 diagnostics: 5 errors + 3 warnings).What changed
Add
tyas a dev toolpyproject.toml/uv.lock—ty==0.0.38in thedevgroup, alongsideruff,pytest, andpytz. Run withuv run ty check us.Real fixes (preferred over suppression)
us/states.py— removed unused# type: ignoreonimport jellyfish. Restructuredlookup()sofallback_keyis no longer initialized toNoneand then reassigned tostr— it is now only bound inside thefallback_func is not Nonebranch, which is the only branch that reads it. Eliminates theNone | strdict-key write that ty was correctly flagging.us/cli/states.py—state.shapefile_urls()legitimately returnsOptional[Dict[str, str]]; guard the iteration with aurls is not Nonecheck.us/tests/test_us.py— removed unused# type: ignoredirectives onjellyfishandpytest; added the sameshapefile_urls()Noneguard inside the (skipped)test_head; addedassert state.fips is not Noneinsidetest_county_fips_prefixed_by_stateto narrowOptional[str]beforestartswithand give a clearer failure message if the invariant ever breaks.Narrow suppression
us/tests/test_us.py— theimport requestsinside the permanently@pytest.mark.skippedtest_headis suppressed with# ty: ignore[unresolved-import]and a one-line note.requestsis intentionally not declared as a dependency, so a real fix would mean adding a dev dependency for code that never runs.Annotations left alone (on purpose)
State.fips: Optional[str]stays optional — obsolete states genuinely lack a FIPS code.shapefile_urls() -> Optional[Dict[str, str]]stays optional — same reason. Callers narrow at the use site instead of changing the public contract.Test plan
uv run ty check us—All checks passed!uv run pytest— 35 passed, 1 skippeduv run ruff check—All checks passed!