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.
Activity