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