@@ -576,7 +576,7 @@ def has_default(self) -> bool:
576576class TypeVarType (TypeVarLikeType ):
577577 """Type that refers to a type variable."""
578578
579- __slots__ = ("values" , "variance" )
579+ __slots__ = ("values" , "variance" , "narrowed" )
580580
581581 values : list [Type ] # Value restriction, empty list if no restriction
582582 variance : int
@@ -592,11 +592,14 @@ def __init__(
592592 variance : int = INVARIANT ,
593593 line : int = - 1 ,
594594 column : int = - 1 ,
595+ * ,
596+ narrowed : bool = False ,
595597 ) -> None :
596598 super ().__init__ (name , fullname , id , upper_bound , default , line , column )
597599 assert values is not None , "No restrictions must be represented by empty list"
598600 self .values = values
599601 self .variance = variance
602+ self .narrowed = narrowed
600603
601604 def copy_modified (
602605 self ,
@@ -607,6 +610,7 @@ def copy_modified(
607610 id : Bogus [TypeVarId | int ] = _dummy ,
608611 line : int = _dummy_int ,
609612 column : int = _dummy_int ,
613+ narrowed : Bogus [bool ] = _dummy ,
610614 ** kwargs : Any ,
611615 ) -> TypeVarType :
612616 return TypeVarType (
@@ -619,6 +623,7 @@ def copy_modified(
619623 variance = self .variance ,
620624 line = self .line if line == _dummy_int else line ,
621625 column = self .column if column == _dummy_int else column ,
626+ narrowed = self .narrowed if narrowed is _dummy else narrowed ,
622627 )
623628
624629 def accept (self , visitor : TypeVisitor [T ]) -> T :
@@ -3047,7 +3052,7 @@ def visit_type_var(self, t: TypeVarType) -> str:
30473052 else :
30483053 # Named type variable type.
30493054 s = f"{ t .name } `{ t .id } "
3050- if self .id_mapper and t .upper_bound :
3055+ if ( self .id_mapper or t . narrowed ) and t .upper_bound :
30513056 s += f"(upper_bound={ t .upper_bound .accept (self )} )"
30523057 return s
30533058
0 commit comments