1414class PydanticAdapter (BasePydanticAdapter [T ]):
1515 """Adapter around a KVStore-compliant Store that allows type-safe persistence of Pydantic models."""
1616
17- # Beartype doesn't like our ` type[T] includes a bound on Sequence[...] as the subscript is not checkable at runtime
18- # For just the next 20 or so lines we are no longer bear bros but have no fear, we will be back soon!
17+ # Beartype cannot handle the parameterized type annotation (type[T]) used here for this generic adapter.
18+ # Using @bear_spray to bypass beartype's runtime checks for this specific method.
1919 @bear_spray
2020 def __init__ (
2121 self ,
@@ -32,12 +32,19 @@ def __init__(
3232 default_collection: The default collection to use.
3333 raise_on_validation_error: Whether to raise a DeserializationError if validation fails during reads. Otherwise,
3434 calls will return None if validation fails.
35- """
3635
36+ Raises:
37+ TypeError: If pydantic_model is a sequence type other than list (e.g., tuple is not supported).
38+ """
3739 self ._key_value = key_value
3840
3941 origin = get_origin (pydantic_model )
40- self ._is_list_model = origin is not None and isinstance (origin , type ) and issubclass (origin , Sequence )
42+ self ._is_list_model = origin is list
43+
44+ # Validate that if it's a generic type, it must be a list (not tuple, etc.)
45+ if origin is not None and origin is not list :
46+ msg = f"Only list[BaseModel] is supported for sequence types, got { pydantic_model } "
47+ raise TypeError (msg )
4148
4249 self ._type_adapter = TypeAdapter [T ](pydantic_model )
4350 self ._default_collection = default_collection
0 commit comments