chore: simplify TypeAdapter

This commit is contained in:
Sagar Vora 2025-07-03 16:14:00 +05:30
parent df950df470
commit fa7e9ebb75

View file

@ -5,7 +5,8 @@ from types import EllipsisType
from typing import ForwardRef, TypeVar, Union
from unittest import mock
from pydantic import ConfigDict
from pydantic import ConfigDict, PydanticUserError
from pydantic import TypeAdapter as PyTypeAdapter
from frappe.exceptions import FrappeTypeError
@ -74,18 +75,14 @@ def raise_type_error(
@lru_cache(maxsize=2048)
def TypeAdapter(type_):
from pydantic import PydanticUserError
from pydantic import TypeAdapter as PyTypeAdapter
try:
return PyTypeAdapter(type_, config=FrappePydanticConfig)
except PydanticUserError as e:
match e.code:
case "type-adapter-config-unused":
# Unless they set their custom __pydantic_config__, this will be the case on BaseModule, TypedDict and dataclass - ignore
return PyTypeAdapter(type_)
case _:
raise e
# Cannot set config for types BaseModel, TypedDict and dataclass
if e.code == "type-adapter-config-unused":
return PyTypeAdapter(type_)
raise e
def transform_parameter_types(func: Callable, args: tuple, kwargs: dict):