Skip to content

fix: adopt ty 0.0.73 optional-import inference - #156

Merged
lesnik512 merged 1 commit into
mainfrom
fix/ty-0.0.73-optional-asyncpg-import
Aug 20, 2026
Merged

fix: adopt ty 0.0.73 optional-import inference#156
lesnik512 merged 1 commit into
mainfrom
fix/ty-0.0.73-optional-asyncpg-import

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Fixes #155.

What broke

The weekly dependency check's lint job failed on run 32002388707; every pytest job passed. ty 0.0.73 (2026-08-18) changed how it infers the optional-import fallback in faststream_outbox/subscriber/usecase.py:

try:
    import asyncpg as _asyncpg
except ImportError:  # pragma: no cover
    _asyncpg = None  # ty: ignore[invalid-assignment]

It no longer errors on the assignment; it widens _asyncpg to <module 'asyncpg'> | None. That produced 4 diagnostics:

  • warning[unused-ignore-comment] — the invalid-assignment ignore no longer suppresses anything (:52).
  • error[unresolved-attribute] x3 — the module-level annotations "_asyncpg.Connection" at :359, :418, :462 now resolve against the union, and the None arm has no Connection.

The in-function uses at :440/:443 were unaffected, because the if _asyncpg is None: return None guard at :431 narrows them.

Fix

Split the type name from the runtime name. _asyncpg stays the guarded, nullable runtime handle; asyncpg joins the existing if typing.TYPE_CHECKING: block and backs the annotations — the same treatment AsyncConnection / AsyncEngine already get in this file. No runtime behavior change, no public API change, no test change (tests/test_unit.py patches ..._asyncpg.connect, a name this PR leaves alone).

Pinning ty<0.0.73 was considered and rejected: just install runs uv lock --upgrade and the lint group deliberately floats ruff/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 the CLAUDE.md link retargeted. The link would otherwise 404 on a case-sensitive checkout. The Justfile mentions left in planning/ are historical records of past changes and are intentionally untouched.

Verification

Run locally on this branch:

  • just lint-cieof-fixer, ruff format --check, ruff check --no-fix, ty check, planning/index.py --check all 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.

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.
@github-actions

Copy link
Copy Markdown

Benchmark gate

✅ gate passed

scenario msg/s delete/msg WALrec/msg WALB/msg fpi upd del dead_tup
consumer/w1/b10 839 1.000 6.79 916 242 5000 5000 10000
consumer/w1/b100 883 1.000 6.84 920 243 5000 5000 10000
consumer/w2/b10 990 1.000 6.80 965 242 5000 5000 10000
consumer/w2/b100 1253 1.000 6.78 997 263 5000 5000 10000
consumer/w4/b10 885 1.000 6.73 942 243 5000 5000 10000
consumer/w4/b100 1420 1.000 6.87 1037 243 5000 5000 10000
consumer/w1/b100/tfbs100 4828 0.010 6.07 1116 243 5000 5000 10000
producer/w1/b100 2177 0.000 3.04 584 0 0 0 0

Gated (fails the build): delete_calls + tuple counters (upd/del/ins) + the producer's insert_calls/select_calls, exact; wal_records within a 10% band. msg/s, WAL bytes and total calls are informational (timing/FPI noise).

@lesnik512
lesnik512 merged commit 6f8a279 into main Aug 20, 2026
8 checks passed
@lesnik512
lesnik512 deleted the fix/ty-0.0.73-optional-asyncpg-import branch August 20, 2026 12:43
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.

Scheduled dependency check failed

1 participant