Skip to content

Commit

Permalink
perf: cache TypeAdapters (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Mar 18, 2024
1 parent 41b6fee commit 2005076
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,12 @@ class GenericModel(BaseGenericModel, BaseModel):


if PYDANTIC_V2:

if TYPE_CHECKING:
from pydantic import TypeAdapter
from pydantic import TypeAdapter
else:
from pydantic import TypeAdapter as _TypeAdapter
TypeAdapter = lru_cache(_TypeAdapter)
from pydantic import TypeAdapter as _TypeAdapter

TypeAdapter = lru_cache(_TypeAdapter)

def _validate_non_model_type(*, type_: type[_T], value: object) -> _T:
return TypeAdapter(type_).validate_python(value)
Expand Down

0 comments on commit 2005076

Please sign in to comment.