Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
3 changes: 3 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,9 @@ def check_generator_or_comprehension(self, gen: GeneratorExpr,
with self.chk.binder.frame_context(can_skip=True, fall_through=0):
self.check_for_comp(gen)

# Check `left_expr` to analyze variables introduced by `AssignmentExpr` if any
gen.left_expr.accept(self)

# Infer the type of the list comprehension by using a synthetic generic
# callable type.
tv = TypeVarType('T', 'T', -1, [], self.object_type())
Expand Down
25 changes: 25 additions & 0 deletions test-data/unit/check-python38.test
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,28 @@ def foo() -> None:
x = 0
[x := x + y for y in [1, 2, 3]]
[builtins fixtures/dict.pyi]

[case testWalrusUndefinedRecursiveReference1]
(x := x) # E: Cannot determine type of "x"

[case testWalrusUndefinedRecursiveReference2]
z = [x := x for y in [1, 2, 3]] # E: Cannot determine type of "x"

[case testWalrusUndefinedRecursiveReference3]
from typing import Any

def f(x: Any) -> None:
pass

f(x := x) # E: Cannot determine type of "x"

[case testWalrusUndefinedRecursiveReference4]
from typing import TypeVar

T = TypeVar("T")

def f(x: T) -> None:
pass

# TODO: should be the same error as others?
f(x := x)