fix: adopt ty 0.0.73 optional-import inference - #156
Merged
Conversation
ty 0.0.73 stopped erroring on the `_asyncpg = None` ImportError fallback and instead widens the name to `<module 'asyncpg'> | None`. Two knock-ons: the `# ty: ignore[invalid-assignment]` became an unused directive, and the three module-level `"_asyncpg.Connection"` annotations turned into `unresolved-attribute` errors because the `None` arm has no `Connection`. The in-function uses were unaffected — the `if _asyncpg is None` guard narrows them. Split the type name from the runtime name: `_asyncpg` stays the guarded, nullable runtime handle, while `asyncpg` joins the existing `TYPE_CHECKING` block and backs the annotations, matching how `AsyncConnection`/`AsyncEngine` are already handled in this file. No runtime behavior change. Also rename `Justfile` to `justfile` and retarget the CLAUDE.md link, which would otherwise 404 on a case-sensitive checkout.
Benchmark gate✅ gate passed
Gated (fails the build): |
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.
Fixes #155.
What broke
The weekly dependency check's
lintjob failed on run 32002388707; every pytest job passed.ty 0.0.73(2026-08-18) changed how it infers the optional-import fallback infaststream_outbox/subscriber/usecase.py:It no longer errors on the assignment; it widens
_asyncpgto<module 'asyncpg'> | None. That produced 4 diagnostics:warning[unused-ignore-comment]— theinvalid-assignmentignore no longer suppresses anything (:52).error[unresolved-attribute]x3 — the module-level annotations"_asyncpg.Connection"at:359,:418,:462now resolve against the union, and theNonearm has noConnection.The in-function uses at
:440/:443were unaffected, because theif _asyncpg is None: return Noneguard at:431narrows them.Fix
Split the type name from the runtime name.
_asyncpgstays the guarded, nullable runtime handle;asyncpgjoins the existingif typing.TYPE_CHECKING:block and backs the annotations — the same treatmentAsyncConnection/AsyncEnginealready get in this file. No runtime behavior change, no public API change, no test change (tests/test_unit.pypatches..._asyncpg.connect, a name this PR leaves alone).Pinning
ty<0.0.73was considered and rejected:just installrunsuv lock --upgradeand thelintgroup deliberately floatsruff/ty, so #153 set the precedent of adopting the upgrade. The new inference is also the more correct one.Planning lane: Tiny (linter tweak, no change file) — same as #153.
Drive-by
Justfile->justfile, with theCLAUDE.mdlink retargeted. The link would otherwise 404 on a case-sensitive checkout. TheJustfilementions left inplanning/are historical records of past changes and are intentionally untouched.Verification
Run locally on this branch:
just lint-ci—eof-fixer,ruff format --check,ruff check --no-fix,ty check,planning/index.py --checkall pass.uv run pytest tests/test_unit.py tests/test_fake.py tests/test_client_contract.py --no-cov— 400 passed, 18 skipped.Not run locally:
just test(the full suite incl.tests/test_integration.py) — no Docker or local Postgres on this machine. CI covers it across 3.11-3.14 + free-threaded.