Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the type for assignment expr targets #9479

Merged
merged 3 commits into from Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mypy/checkexpr.py
Expand Up @@ -3788,6 +3788,9 @@ def accept(self,
assert typ is not None
self.chk.store_type(node, typ)

if isinstance(node, AssignmentExpr) and not has_uninhabited_component(typ):
self.chk.store_type(node.target, typ)

if (self.chk.options.disallow_any_expr and
not always_allow_any and
not self.chk.is_stub and
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-python38.test
Expand Up @@ -377,3 +377,13 @@ def check_partial_list() -> None:
z.append(3)
reveal_type(z) # N: Revealed type is 'builtins.list[builtins.int]'
[builtins fixtures/list.pyi]

[case testWalrusExpr]
def func() -> None:
foo = Foo()
if x := foo.x:
pass

class Foo:
def __init__(self) -> None:
self.x = 123