@@ -2619,20 +2619,22 @@ def check_assignment(
26192619
26202620 # Special case: only non-abstract non-protocol classes can be assigned to
26212621 # variables with explicit type Type[A], where A is protocol or abstract.
2622- rvalue_type = get_proper_type (rvalue_type )
2623- lvalue_type = get_proper_type (lvalue_type )
2622+ p_rvalue_type = get_proper_type (rvalue_type )
2623+ p_lvalue_type = get_proper_type (lvalue_type )
26242624 if (
2625- isinstance (rvalue_type , CallableType )
2626- and rvalue_type .is_type_obj ()
2625+ isinstance (p_rvalue_type , CallableType )
2626+ and p_rvalue_type .is_type_obj ()
26272627 and (
2628- rvalue_type .type_object ().is_abstract
2629- or rvalue_type .type_object ().is_protocol
2628+ p_rvalue_type .type_object ().is_abstract
2629+ or p_rvalue_type .type_object ().is_protocol
2630+ )
2631+ and isinstance (p_lvalue_type , TypeType )
2632+ and isinstance (p_lvalue_type .item , Instance )
2633+ and (
2634+ p_lvalue_type .item .type .is_abstract or p_lvalue_type .item .type .is_protocol
26302635 )
2631- and isinstance (lvalue_type , TypeType )
2632- and isinstance (lvalue_type .item , Instance )
2633- and (lvalue_type .item .type .is_abstract or lvalue_type .item .type .is_protocol )
26342636 ):
2635- self .msg .concrete_only_assign (lvalue_type , rvalue )
2637+ self .msg .concrete_only_assign (p_lvalue_type , rvalue )
26362638 return
26372639 if rvalue_type and infer_lvalue_type and not isinstance (lvalue_type , PartialType ):
26382640 # Don't use type binder for definitions of special forms, like named tuples.
@@ -3474,7 +3476,6 @@ def infer_variable_type(
34743476 self , name : Var , lvalue : Lvalue , init_type : Type , context : Context
34753477 ) -> None :
34763478 """Infer the type of initialized variables from initializer type."""
3477- init_type = get_proper_type (init_type )
34783479 if isinstance (init_type , DeletedType ):
34793480 self .msg .deleted_as_rvalue (init_type , context )
34803481 elif not is_valid_inferred_type (init_type ) and not self .no_partial_types :
@@ -3620,23 +3621,21 @@ def check_simple_assignment(
36203621 # '...' is always a valid initializer in a stub.
36213622 return AnyType (TypeOfAny .special_form )
36223623 else :
3623- orig_lvalue = lvalue_type
3624- lvalue_type = get_proper_type (lvalue_type )
3625- always_allow_any = lvalue_type is not None and not isinstance ( lvalue_type , AnyType )
3624+ always_allow_any = lvalue_type is not None and not isinstance (
3625+ get_proper_type (lvalue_type ), AnyType
3626+ )
36263627 rvalue_type = self .expr_checker .accept (
36273628 rvalue , lvalue_type , always_allow_any = always_allow_any
36283629 )
3629- orig_rvalue = rvalue_type
3630- rvalue_type = get_proper_type (rvalue_type )
36313630 if isinstance (rvalue_type , DeletedType ):
36323631 self .msg .deleted_as_rvalue (rvalue_type , context )
36333632 if isinstance (lvalue_type , DeletedType ):
36343633 self .msg .deleted_as_lvalue (lvalue_type , context )
36353634 elif lvalue_type :
36363635 self .check_subtype (
36373636 # Preserve original aliases for error messages when possible.
3638- orig_rvalue ,
3639- orig_lvalue or lvalue_type ,
3637+ rvalue_type ,
3638+ lvalue_type ,
36403639 context ,
36413640 msg ,
36423641 f"{ rvalue_name } has type" ,
0 commit comments