1313 Literal ,
1414 TypeVar ,
1515 Union ,
16+ Sequence ,
1617 _SpecialForm , # pyright: ignore[reportPrivateUsage]
1718)
1819
@@ -43,7 +44,7 @@ class TypeView(Generic[T]):
4344 "_wrappers" : "A set of wrapper types that were removed from the annotation." ,
4445 }
4546
46- def __init__ (self , annotation : T ) -> None :
47+ def __init__ (self , annotation : T , * , metadata : Sequence [ Any ] = () ) -> None :
4748 """Initialize ParsedType.
4849
4950 Args:
@@ -54,7 +55,7 @@ def __init__(self, annotation: T) -> None:
5455 Returns:
5556 ParsedType
5657 """
57- unwrapped , metadata , wrappers = unwrap_annotation (annotation )
58+ unwrapped , annotation_metadata , wrappers = unwrap_annotation (annotation )
5859 origin = get_origin (unwrapped )
5960
6061 args : tuple [Any , ...] = () if origin is abc .Callable else get_args (unwrapped ) # pyright: ignore
@@ -64,9 +65,9 @@ def __init__(self, annotation: T) -> None:
6465 self .origin : Final [Any ] = origin
6566 self .fallback_origin : Final [Any ] = origin or unwrapped
6667 self .args : Final [tuple [Any , ...]] = args
67- self .metadata : Final = metadata
68+ self .metadata : Final = ( * annotation_metadata , * metadata )
6869 self ._wrappers : Final = wrappers
69- self .inner_types : Final = tuple (TypeView (arg ) for arg in args )
70+ self .inner_types : Final = tuple (TypeView (arg , metadata = self . metadata ) for arg in args )
7071
7172 def __eq__ (self , other : object ) -> bool :
7273 if not isinstance (other , TypeView ):
@@ -285,7 +286,7 @@ def strip_optional(self) -> TypeView[Any]:
285286
286287 args = tuple (a for a in self .args if a is not NoneType )
287288 non_optional = Union [args ] # type: ignore[valid-type]
288- return TypeView (non_optional )
289+ return TypeView (non_optional , metadata = self . metadata )
289290
290291 def strip_type_alias (self ) -> TypeView [Any ]:
291292 """Remove the type alias from a `type Type = T` type alias.
@@ -297,7 +298,7 @@ def strip_type_alias(self) -> TypeView[Any]:
297298 """
298299 if not self .is_type_alias :
299300 return self
300- return TypeView (self .annotation .__value__ )
301+ return TypeView (self .annotation .__value__ , metadata = self . metadata )
301302
302303
303304def _is_typing_extensins_type_alias (type_view : TypeView [Any ]) -> bool :
0 commit comments