|
32 | 32 | cast, |
33 | 33 | ) |
34 | 34 |
|
35 | | -from pydantic import GetCoreSchemaHandler |
36 | | -from pydantic_core import CoreSchema, core_schema |
| 35 | +try: |
| 36 | + import pydantic |
| 37 | + import pydantic_core |
| 38 | + |
| 39 | + HAVE_PYDANTIC = True |
| 40 | +except ImportError: |
| 41 | + HAVE_PYDANTIC = False |
37 | 42 |
|
38 | 43 | import temporalio.workflow |
39 | 44 |
|
@@ -986,7 +991,7 @@ def __init__(self, *args, **kwargs) -> None: |
986 | 991 | _trace("__init__ unrecognized with args %s", args) |
987 | 992 |
|
988 | 993 | def __getattribute__(self, __name: str) -> Any: |
989 | | - if __name == "__get_pydantic_core_schema__": |
| 994 | + if HAVE_PYDANTIC and __name == "__get_pydantic_core_schema__": |
990 | 995 | return object.__getattribute__(self, "__get_pydantic_core_schema__") |
991 | 996 | state = _RestrictionState.from_proxy(self) |
992 | 997 | _trace("__getattribute__ %s on %s", __name, state.name) |
@@ -1037,14 +1042,17 @@ def __getitem__(self, key: Any) -> Any: |
1037 | 1042 | ) |
1038 | 1043 | return ret |
1039 | 1044 |
|
1040 | | - # Instruct pydantic to use the proxied type when determining the schema |
1041 | | - @classmethod |
1042 | | - def __get_pydantic_core_schema__( |
1043 | | - cls, source_type: Any, handler: GetCoreSchemaHandler |
1044 | | - ) -> CoreSchema: |
1045 | | - return core_schema.no_info_after_validator_function( |
1046 | | - cls, handler(RestrictionContext.unwrap_if_proxied(source_type)) |
1047 | | - ) |
| 1045 | + if HAVE_PYDANTIC: |
| 1046 | + # Instruct pydantic to use the proxied type when determining the schema |
| 1047 | + @classmethod |
| 1048 | + def __get_pydantic_core_schema__( |
| 1049 | + cls, |
| 1050 | + source_type: Any, |
| 1051 | + handler: pydantic.GetCoreSchemaHandler, |
| 1052 | + ) -> pydantic_core.CoreSchema: |
| 1053 | + return pydantic_core.core_schema.no_info_after_validator_function( |
| 1054 | + cls, handler(RestrictionContext.unwrap_if_proxied(source_type)) |
| 1055 | + ) |
1048 | 1056 |
|
1049 | 1057 | __doc__ = _RestrictedProxyLookup( # type: ignore |
1050 | 1058 | class_value=__doc__, fallback_func=lambda self: type(self).__doc__, is_attr=True |
|
0 commit comments