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
Attribute writes inside a loop are ignored after the loop #5767
When a loop assigns to an attribute, Pyrefly ignores that assignment after the loop and keeps the attribute's type from before the loop. This causes false positives and hides real errors.
classStats:
defmean(self, values: list[int]) ->float:
self.count=0for_invalues:
self.count+=1return10/self.countifself.count>0else0.0# warning: Cannot divide by zero: `/` with a literal zero divisorclassSlot:
value: int|None=Nonedefbump(slot: Slot, items: list[int]) ->int:
slot.value=0for_initems:
slot.value=Nonereturnslot.value+1# no error, but this raises TypeError when `items` is not empty
Expected:
self.count is int after the loop, so the guarded division is accepted.
slot.value is int | None after the loop, so slot.value + 1 is an error.
reveal_type(self.count) shows Literal[0] both inside the loop and after it. Item assignments such as values[0] = None are ignored the same way. Plain local variables work as expected.
Activity
synnks commentedon Nov 25, 2026
#claim
github-actions commentedon Nov 25, 2026
@synnks you've claimed this issue — it's now assigned to you. Thanks for picking it up! 🎉