You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inferred attribute type feeds back as call context, rejecting its own defining assignment #21809
Assigning a generic call returning K | None to a previously undeclared self. attribute spuriously fails [arg-type] on that same assignment. The
attribute's inferred type (str | None) apparently comes back as call context
on a later pass, solving K = str | None; the invariant Mapping key then
rejects dict[str, str].
The same expression passes with no context, an annotated local, an annotated
attribute, or a reassigned local (whose second assignment is likewise checked
against its own inferred str | None) — the optional-stripping special case
seems skipped on the inferred-attribute path alone. A sync version (no async/await) also passes, pointing at the deferred re-check await
triggers.
repro.py:10: error: Argument 1 to "select_one" has incompatible type "dict[str, str]"; expected "Mapping[str | None, str]" [arg-type]
The str | None key shows the return's | None leaked into K.
Your Environment
mypy 1.20.2 (compiled), no flags
Python 3.13
Related: #5874 (over-eager outer context with unions), #19304 (assignment target
changes results). New here: the context is self-inferred — no annotation exists
anywhere — and explicit spellings of the same type behave differently.
I have added a unit test reproducing this particular usecase to my PR for #19304here. I have confirmed the test fails in master but passes with the fixes found in the PR.
Activity
rheard commentedon Aug 6, 2026
Hello @Kache , thank you for the bug report.
I have added a unit test reproducing this particular usecase to my PR for #19304 here. I have confirmed the test fails in master but passes with the fixes found in the PR.
Have a great day,
Ryan.