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
var-annotated errors for iteration should point to the line where the variable is defined #22265
This error is actually kind-of pointless in this case, since you cannot add an annotation inside a comprehension. Instead, we should say something different for a variable in comprehension.
fromtypingimportNeverx: Nevery: int# or whateversum(yforyinx)
but obviously that runs into the fact the annotation doesn't actually get persisted through -- kinda surprising until you remember narrowing behavior can vary based on whether the assignment has a declared type!
@A5rocks I am not sure you understand: mypy still shows Need type annotation for "y" in your example, because y outside comprehension, and y inside comprehension are two different variables (because comprehensions introduce a new scope).
Activity
ilevkivskyi commentedon Oct 22, 2026
This error is actually kind-of pointless in this case, since you cannot add an annotation inside a comprehension. Instead, we should say something different for a variable in comprehension.
A5rocks commentedon Oct 23, 2026
Yeah in these cases I've been resorting to:
but obviously that runs into the fact the annotation doesn't actually get persisted through -- kinda surprising until you remember narrowing behavior can vary based on whether the assignment has a declared type!
ilevkivskyi commentedon Oct 23, 2026
@A5rocks I am not sure you understand: mypy still shows
Need type annotation for "y"in your example, becauseyoutside comprehension, andyinside comprehension are two different variables (because comprehensions introduce a new scope).