Skip to content

Commit 1574a5f

Browse files
committed
narrow unions on initial assignment
1 parent 5f3e6ec commit 1574a5f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

mypy/checker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3212,7 +3212,13 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
32123212
# as X | Y.
32133213
if not (s.is_alias_def and self.is_stub):
32143214
with self.enter_final_context(s.is_final_def):
3215-
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
3215+
self.check_assignment(
3216+
s.lvalues[-1],
3217+
s.rvalue,
3218+
infer_lvalue_type=s.type is None
3219+
or isinstance(get_proper_type(s.type), UnionType),
3220+
new_syntax=s.new_syntax,
3221+
)
32163222

32173223
if s.is_alias_def:
32183224
self.check_type_alias_rvalue(s)

0 commit comments

Comments
 (0)