Skip to content

Commit 08a4409

Browse files
committed
Dont import TypeAdapter if we have it, speed up type_adapter call ~4x
Signed-off-by: Nijat Khanbabayev <[email protected]>
1 parent 9a9703f commit 08a4409

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

csp/impl/struct.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ def serializer(val, handler):
149149
class Struct(_csptypesimpl.PyStruct, metaclass=StructMeta):
150150
@classmethod
151151
def type_adapter(cls):
152-
# Late import to avoid autogen issues
153-
from pydantic import TypeAdapter
154-
155152
internal_type_adapter = getattr(cls, "_pydantic_type_adapter", None)
156153
if internal_type_adapter:
157154
return internal_type_adapter
155+
156+
# Late import to avoid autogen issues
157+
from pydantic import TypeAdapter
158+
158159
cls._pydantic_type_adapter = TypeAdapter(cls)
159160
return cls._pydantic_type_adapter
160161

0 commit comments

Comments
 (0)