diff --git a/mypy/checker.py b/mypy/checker.py index 3f2a8476ed934..7239082a21c2f 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -5760,7 +5760,7 @@ def visit_for_stmt(self, s: ForStmt) -> None: s.body, s.else_body, on_enter_body=lambda: self.analyze_index_variables( - s.index, item_type, s.index_type is None, s + s.index, item_type, s.index_type is None, s.index ), ) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 2ed757eeeaa83..86086e09acf75 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -6109,7 +6109,7 @@ def check_for_comp(self, e: GeneratorExpr | DictionaryComprehension) -> None: # To preserve backward compatibility, avoid inferring Never for "_" sequence_type = AnyType(TypeOfAny.special_form) - self.chk.analyze_index_variables(index, sequence_type, True, e) + self.chk.analyze_index_variables(index, sequence_type, True, index) for condition in conditions: self.accept(condition)