@@ -704,8 +704,8 @@ def visit_instance(self, t: Instance) -> None:
704
704
arg_values = [arg ]
705
705
self .check_type_var_values (info , arg_values , tvar .name , tvar .values , i + 1 , t )
706
706
# TODO: These hacks will be not necessary when this will be moved to later stage.
707
- arg = self .update_type (arg )
708
- bound = self .update_type (tvar .upper_bound )
707
+ arg = self .resolve_type (arg )
708
+ bound = self .resolve_type (tvar .upper_bound )
709
709
if not is_subtype (arg , bound ):
710
710
self .fail ('Type argument "{}" of "{}" must be '
711
711
'a subtype of "{}"' .format (
@@ -719,9 +719,10 @@ def visit_instance(self, t: Instance) -> None:
719
719
def check_type_var_values (self , type : TypeInfo , actuals : List [Type ], arg_name : str ,
720
720
valids : List [Type ], arg_number : int , context : Context ) -> None :
721
721
for actual in actuals :
722
- actual = self .update_type (actual )
722
+ actual = self .resolve_type (actual )
723
723
if (not isinstance (actual , AnyType ) and
724
- not any (is_same_type (actual , self .update_type (value )) for value in valids )):
724
+ not any (is_same_type (actual , self .resolve_type (value ))
725
+ for value in valids )):
725
726
if len (actuals ) > 1 or not isinstance (actual , Instance ):
726
727
self .fail ('Invalid type argument value for "{}"' .format (
727
728
type .name ()), context )
@@ -731,11 +732,13 @@ def check_type_var_values(self, type: TypeInfo, actuals: List[Type], arg_name: s
731
732
self .fail (messages .INCOMPATIBLE_TYPEVAR_VALUE .format (
732
733
arg_name , class_name , actual_type_name ), context )
733
734
734
- def update_type (self , tp : Type ) -> Type :
735
+ def resolve_type (self , tp : Type ) -> Type :
735
736
# This helper is only needed while is_subtype and is_same_type are
736
737
# called in third pass. This can be removed when TODO in visit_instance is fixed.
737
738
if isinstance (tp , ForwardRef ):
738
- tp = tp .link
739
+ if tp .resolved is None :
740
+ return tp .unbound
741
+ tp = tp .resolved
739
742
if isinstance (tp , Instance ) and tp .type .replaced :
740
743
replaced = tp .type .replaced
741
744
if replaced .tuple_type :
@@ -799,8 +802,9 @@ def visit_type_type(self, t: TypeType) -> None:
799
802
800
803
def visit_forwardref_type (self , t : ForwardRef ) -> None :
801
804
self .indicator ['forward' ] = True
802
- if isinstance (t .link , UnboundType ):
803
- t .link = self .anal_type (t .link )
805
+ if t .resolved is None :
806
+ resolved = self .anal_type (t .unbound )
807
+ t .resolve (resolved )
804
808
805
809
def anal_type (self , tp : UnboundType ) -> Type :
806
810
tpan = TypeAnalyser (self .lookup_func ,
0 commit comments