|
48 | 48 | ) |
49 | 49 | from mypy.types import ( |
50 | 50 | AnyType, |
| 51 | + DeletedType, |
51 | 52 | Instance, |
52 | 53 | ProperType, |
53 | 54 | TupleType, |
@@ -573,21 +574,22 @@ def get_assignment_target( |
573 | 574 | self.error("Cannot assign to the first argument of classmethod", line) |
574 | 575 | if lvalue.kind == LDEF: |
575 | 576 | if symbol not in self.symtables[-1]: |
| 577 | + if isinstance(symbol, Var) and not isinstance(symbol.type, DeletedType): |
| 578 | + reg_type = self.type_to_rtype(symbol.type) |
| 579 | + else: |
| 580 | + reg_type = self.node_type(lvalue) |
576 | 581 | # If the function is a generator function, then first define a new variable |
577 | 582 | # in the current function's environment class. Next, define a target that |
578 | 583 | # refers to the newly defined variable in that environment class. Add the |
579 | 584 | # target to the table containing class environment variables, as well as the |
580 | 585 | # current environment. |
581 | 586 | if self.fn_info.is_generator: |
582 | 587 | return self.add_var_to_env_class( |
583 | | - symbol, |
584 | | - self.node_type(lvalue), |
585 | | - self.fn_info.generator_class, |
586 | | - reassign=False, |
| 588 | + symbol, reg_type, self.fn_info.generator_class, reassign=False |
587 | 589 | ) |
588 | 590 |
|
589 | 591 | # Otherwise define a new local variable. |
590 | | - return self.add_local_reg(symbol, self.node_type(lvalue)) |
| 592 | + return self.add_local_reg(symbol, reg_type) |
591 | 593 | else: |
592 | 594 | # Assign to a previously defined variable. |
593 | 595 | return self.lookup(symbol) |
|
0 commit comments