@@ -5637,13 +5637,20 @@ def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
56375637 else :
56385638 incomplete_target = has_placeholder (res )
56395639
5640- incomplete_tv = any (has_placeholder (tv ) for tv in alias_tvars )
5641- if self .found_incomplete_ref (tag ) or incomplete_target or incomplete_tv :
5640+ if self .found_incomplete_ref (tag ) or incomplete_target :
56425641 # Since we have got here, we know this must be a type alias (incomplete refs
56435642 # may appear in nested positions), therefore use becomes_typeinfo=True.
56445643 self .mark_incomplete (s .name .name , s .value , becomes_typeinfo = True )
56455644 return
56465645
5646+ # Now go through all new variables and temporary replace all tvars that still
5647+ # refer to some placeholders. We defer the whole alias and will revisit it again,
5648+ # as well as all its dependents.
5649+ for i , tv in enumerate (alias_tvars ):
5650+ if has_placeholder (tv ):
5651+ self .mark_incomplete (s .name .name , s .value , becomes_typeinfo = True )
5652+ alias_tvars [i ] = self ._trivial_typevarlike_like (tv )
5653+
56475654 self .add_type_alias_deps (depends_on )
56485655 check_for_explicit_any (
56495656 res , self .options , self .is_typeshed_stub_file , self .msg , context = s
@@ -5677,7 +5684,10 @@ def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
56775684 ):
56785685 updated = False
56795686 if isinstance (existing .node , TypeAlias ):
5680- if existing .node .target != res :
5687+ if (
5688+ existing .node .target != res
5689+ or existing .node .alias_tvars != alias_node .alias_tvars
5690+ ):
56815691 # Copy expansion to the existing alias, this matches how we update base classes
56825692 # for a TypeInfo _in place_ if there are nested placeholders.
56835693 existing .node .target = res
@@ -5707,6 +5717,46 @@ def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
57075717 finally :
57085718 self .pop_type_args (s .type_args )
57095719
5720+ def _trivial_typevarlike_like (self , tv : TypeVarLikeType ) -> TypeVarLikeType :
5721+ object_type = self .named_type ("builtins.object" )
5722+ if isinstance (tv , TypeVarType ):
5723+ return TypeVarType (
5724+ tv .name ,
5725+ tv .fullname ,
5726+ tv .id ,
5727+ values = [],
5728+ upper_bound = object_type ,
5729+ default = AnyType (TypeOfAny .from_omitted_generics ),
5730+ variance = tv .variance ,
5731+ line = tv .line ,
5732+ column = tv .column ,
5733+ )
5734+ elif isinstance (tv , TypeVarTupleType ):
5735+ tuple_type = self .named_type ("builtins.tuple" , [object_type ])
5736+ return TypeVarTupleType (
5737+ tv .name ,
5738+ tv .fullname ,
5739+ tv .id ,
5740+ upper_bound = tuple_type ,
5741+ tuple_fallback = tuple_type ,
5742+ default = AnyType (TypeOfAny .from_omitted_generics ),
5743+ line = tv .line ,
5744+ column = tv .column ,
5745+ )
5746+ elif isinstance (tv , ParamSpecType ):
5747+ return ParamSpecType (
5748+ tv .name ,
5749+ tv .fullname ,
5750+ tv .id ,
5751+ flavor = tv .flavor ,
5752+ upper_bound = object_type ,
5753+ default = AnyType (TypeOfAny .from_omitted_generics ),
5754+ line = tv .line ,
5755+ column = tv .column ,
5756+ )
5757+ else :
5758+ assert False , f"Unknown TypeVarLike: { tv !r} "
5759+
57105760 #
57115761 # Expressions
57125762 #
0 commit comments