@@ -100,9 +100,9 @@ class TsTypeValidator:
100100 For example, this is to make sure that:
101101 ts[List] can validate as ts[List[float]]
102102 ts[Dict[str, List[str]] won't validate as ts[Dict[str, List[float]]
103- ts["T"], ts[TypeVar("T")], ts[List["T"]], etc are allowed
104- ts[Optional[float]] , ts[Union[float, int ]], ts[Annotated [float, None ]], etc are not allowed
105- etc
103+ Notes:
104+ ts["T"], ts[TypeVar("T")] , ts[List["T"]], ts[Optional[float ]], ts[Union [float, int ]], ts[Any] are allowed
105+ ts[Annotated[float, None]], are not allowed
106106 For validation of csp baskets, this piece becomes the bottleneck
107107 """
108108
@@ -126,7 +126,7 @@ def __init__(self, source_type: type):
126126 self ._source_is_union = CspTypingUtils .is_union_type (source_type )
127127 self ._source_args = typing .get_args (source_type )
128128 self ._source_adapter = None
129- if type (source_type ) in (typing .ForwardRef , typing .TypeVar ):
129+ if type (source_type ) in (typing .ForwardRef , typing .TypeVar ) or source_type is typing . Any :
130130 pass # Will handle these separately as part of type checking
131131 elif self ._source_origin is None and isinstance (self ._source_type , type ):
132132 # self._source_adapter = TypeAdapter(typing.Type[source_type])
@@ -163,12 +163,19 @@ def validate(self, value_type, info=None):
163163 self ._last_value_type = value_type
164164 self ._last_context = info .context if info is not None else None
165165
166+ if value_type is typing .Any :
167+ # https://docs.python.org/3/library/typing.html#the-any-type
168+ # "Notice that no type checking is performed when assigning a value of type Any to a more precise type."
169+ return value_type
170+
166171 # Fast path because while we could use the source adapter in the next block to validate,
167172 # it's about 10x faster to do a simple validation with issubclass, and this adds up on baskets
168173 if self ._source_origin is None :
169174 # Want to allow int to be passed for float (i.e. in resolution of TVars)
170175 if self ._source_type is float and value_type is int :
171176 return self ._source_type
177+ if self ._source_type is typing .Any :
178+ return value_type
172179 try :
173180 if issubclass (value_type , self ._source_type ):
174181 return value_type
0 commit comments