We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 32f0502 commit a23112cCopy full SHA for a23112c
1 file changed
mypy/checker.py
@@ -3231,7 +3231,18 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
3231
# as X | Y.
3232
if not (s.is_alias_def and self.is_stub):
3233
with self.enter_final_context(s.is_final_def):
3234
- self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+ self.check_assignment(
3235
+ s.lvalues[-1],
3236
+ s.rvalue,
3237
+ infer_lvalue_type=(
3238
+ s.type is None
3239
+ or (
3240
+ (not isinstance(s.rvalue, TempNode) or not s.rvalue.no_rhs)
3241
+ and isinstance(get_proper_type(s.type), UnionType)
3242
+ )
3243
+ ),
3244
+ new_syntax=s.new_syntax,
3245
3246
3247
if s.is_alias_def:
3248
self.check_type_alias_rvalue(s)
0 commit comments