Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion taskiq/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: noqa
from functools import lru_cache
from typing import Any, Dict, Optional, Type, TypeVar, Union

import pydantic
Expand All @@ -13,8 +14,12 @@
if IS_PYDANTIC2:
T = TypeVar("T")

@lru_cache()
def create_type_adapter(annot: T) -> pydantic.TypeAdapter[T]:
return pydantic.TypeAdapter(annot)

def parse_obj_as(annot: T, obj: Any) -> T:
return pydantic.TypeAdapter(annot).validate_python(obj)
return create_type_adapter(annot).validate_python(obj)

def model_validate(
model_class: Type[Model],
Expand Down