Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6133,7 +6133,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)

Expand Down
60 changes: 60 additions & 0 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,66 @@ for e, f in [[]]: # E: Need type annotation for "e" \

[builtins fixtures/for.pyi]

[case testInferenceOfIndexInMultiLineComprehension]
def f(x: object) -> None: pass

f(
y
for y in [] # E: Need type annotation for "y"
)
a = [
y
for y in [] # E: Need type annotation for "y"
]
b = {
y
for y in [] # E: Need type annotation for "y"
}
c = {
k: 0
for k in [] # E: Need type annotation for "k"
}
d = [
(y, z)
for y in [1]
for z in [] # E: Need type annotation for "z"
]
e = [
y
for y, z in [(1, 2, 3)] # E: Too many values to unpack (2 expected, 3 provided)
]
[builtins fixtures/primitives.pyi]

[case testInferenceOfIndexInMultiLineComprehension_old_parser]
def f(x: object) -> None: pass

f(
y
for y in [] # E: Need type annotation for "y"
)
a = [
y
for y in [] # E: Need type annotation for "y"
]
b = {
y
for y in [] # E: Need type annotation for "y"
}
c = {
k: 0
for k in [] # E: Need type annotation for "k"
}
d = [
(y, z)
for y in [1]
for z in [] # E: Need type annotation for "z"
]
e = [
y
for y, z in [(1, 2, 3)] # E: Too many values to unpack (2 expected, 3 provided)
]
[builtins fixtures/primitives.pyi]

[case testForStatementInferenceWithVoid]
def f() -> None: pass

Expand Down
Loading