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
isinstance() narrowing breaks after unrelated isinstance() check in a returning sibling branch (1.1.0 regression) #3867
isinstance() narrowing of a union variable silently stops working when an earlier sibling branch in the same if/elif/else chain narrows a different variable with isinstance() and returns. The later narrowing leaves the union untouched, producing false missing-attribute errors.
This is a regression: it works correctly in pyrefly 1.0.0 and is broken in 1.1.0 (git bisect came up with 86f0da7 being the culprit).
Inside if isinstance(value, int):, value should narrow to int, as it does in 1.0.0. The isinstance(other, int) check on the unrelated other in the earlier elif should have no effect on value.
Repro
(same as sandbox link)
fromtypingimportreveal_typedeff(cond: bool, other: object, value: int|str) ->None:
ifcond:
passelifisinstance(other, int): # narrows a DIFFERENT variable, in a branch that returnsreturnelse:
returnreveal_type(value) # int | strifisinstance(value, int):
reveal_type(value) # BUG: int | str (should be: int)value.bit_length() # false error: `str` has no attribute `bit_length`
Expected / 1.0.0 behavior
revealed type: int | str
revealed type: int
0 errors
Actual behavior
revealed type: int | str
revealed type: int | str <- should be `int`
ERROR Object of class `str` has no attribute `bit_length` [missing-attribute]
Activity
samwgoldman commentedon Jun 18, 2026
Thanks for the great bug report! Looking now.
Fix isinstance narrowing silently breaking after a sibling branch nar…
samwgoldman commentedon Jun 18, 2026
I'm going to release v1.1.1 with this fix shortly. Thanks again for the report!
Fix isinstance narrowing silently breaking after a sibling branch nar…
cut 1.1.1
cut 1.1.1
friday commentedon Jun 19, 2026
Thank you for the super quick fix and release 🙏
fix(deps+ci): bump msgpack 1.1.2→1.2.1 (CVE fix) + pyrefly 1.0→1.1.1 …
Fix isinstance narrowing silently breaking after a sibling branch nar…
cut 1.1.1