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
Walrus assignment after and loses an earlier narrowing #5763
A walrus assignment on the right of and drops an earlier narrowing. The variable was already narrowed to C. After if flag and (c := find()) is None: return, Pyrefly treats it as C | None again.
On every path past the if, c is a C:
If flag is false, the walrus never runs, so c keeps its earlier narrowed type C.
If flag is true and the walrus result is None, the function returns.
If flag is true and the walrus result is not None, c is C.
$ pyrefly check --preset default min.py
ERROR Argument `C | None` is not assignable to parameter `c` with type `C` in function `use` [bad-argument-type]
--> min.py:11:9
Expected: no error. mypy accepts this code.
Version: pyrefly 1.5.0
It reproduces with --preset default, legacy and strict. --preset basic reports no error.
It also reproduces when the condition is an attribute check, such as c.r.seed is None and (c := await stamp(c)) is None, inside an async def.
@dibrinsofor we couldn't find a merged PR from you, and we only allow multiple simultaneous claims from repeat contributors. You're already assigned to #5647.
I think it touches on some major problems in Pyrefly, including ones related to our binding graph where any mistakes could lead to nondeterminism. I suspect that this is going to have to be solved as part of a major project (as in weeks of full-time work) from someone on the team, likely me.
Activity
github-actions commentedon Nov 26, 2026
@dibrinsofor we couldn't find a merged PR from you, and we only allow multiple simultaneous claims from repeat contributors. You're already assigned to #5647.
TimonGaertner commentedon Nov 26, 2026
#claim
github-actions commentedon Nov 26, 2026
@TimonGaertner you've claimed this issue — it's now assigned to you. Thanks for picking it up! 🎉
Keep an earlier narrowing when a walrus in a later `and` operand does…
stroxler commentedon Nov 28, 2026
Taking this issue along with @TimonGaertner
I think it touches on some major problems in Pyrefly, including ones related to our binding graph where any mistakes could lead to nondeterminism. I suspect that this is going to have to be solved as part of a major project (as in weeks of full-time work) from someone on the team, likely me.