|
11 | 11 | BaseModel, |
12 | 12 | TypeAdapter, |
13 | 13 | model_dump, |
14 | | - pydantic_dataclass, |
15 | 14 | ) |
16 | 15 |
|
17 | 16 | __pydantic_model__ = "__pydantic_core_schema__" |
|
20 | 19 | __skip_filter__ = "__skip_filter__" |
21 | 20 |
|
22 | 21 |
|
23 | | -@t.no_type_check |
24 | | -def get_dataclass_pydantic_model( |
25 | | - dataclass_type: t.Type, |
26 | | -) -> t.Optional[t.Type[BaseModel]]: |
27 | | - if hasattr(dataclass_type, __pydantic_model__): |
28 | | - return t.cast(t.Type[BaseModel], dataclass_type) |
| 22 | +# @t.no_type_check |
| 23 | +# def get_dataclass_pydantic_model( |
| 24 | +# dataclass_type: t.Type, |
| 25 | +# ) -> t.Optional[t.Type[BaseModel]]: |
| 26 | +# if hasattr(dataclass_type, __pydantic_model__): |
| 27 | +# return t.cast(t.Type[BaseModel], dataclass_type) |
| 28 | +# |
| 29 | +# def convert_dataclass_to_pydantic_model(dataclass_type: t.Type) -> t.Type[BaseModel]: |
| 30 | +# if is_dataclass(dataclass_type): |
| 31 | +# if get_dataclass_pydantic_model(dataclass_type): |
| 32 | +# return t.cast(t.Type[BaseModel], dataclass_type) |
| 33 | +# |
| 34 | +# # convert to dataclass |
| 35 | +# decorator = pydantic_dataclass( |
| 36 | +# config=getattr(dataclass_type, __pydantic_config__, SerializerConfig), |
| 37 | +# ) |
| 38 | +# pydantic_dataclass_cls = decorator(t.cast(t.Any, dataclass_type)) |
| 39 | +# # sa = {item: getattr(pydantic_dataclass, item) for item in dir(pydantic_dataclass)} |
| 40 | +# return t.cast(t.Type[BaseModel], pydantic_dataclass_cls) |
| 41 | +# raise Exception(f"{dataclass_type} is not a dataclass") |
29 | 42 |
|
30 | 43 |
|
31 | 44 | class SerializerConfig(BaseConfig): |
@@ -108,21 +121,6 @@ class Serializer(SerializerBase, BaseModel, __skip_filter__=True): |
108 | 121 | model_config = {"from_attributes": True} |
109 | 122 |
|
110 | 123 |
|
111 | | -def convert_dataclass_to_pydantic_model(dataclass_type: t.Type) -> t.Type[BaseModel]: |
112 | | - if is_dataclass(dataclass_type): |
113 | | - if get_dataclass_pydantic_model(dataclass_type): |
114 | | - return t.cast(t.Type[BaseModel], dataclass_type) |
115 | | - |
116 | | - # convert to dataclass |
117 | | - decorator = pydantic_dataclass( |
118 | | - config=getattr(dataclass_type, __pydantic_config__, SerializerConfig), |
119 | | - ) |
120 | | - pydantic_dataclass_cls = decorator(t.cast(t.Any, dataclass_type)) |
121 | | - # sa = {item: getattr(pydantic_dataclass, item) for item in dir(pydantic_dataclass)} |
122 | | - return t.cast(t.Type[BaseModel], pydantic_dataclass_cls) |
123 | | - raise Exception(f"{dataclass_type} is not a dataclass") |
124 | | - |
125 | | - |
126 | 124 | def _lazy_current_config() -> t.Any: |
127 | 125 | return LazyStrImport("ellar.app:current_config") |
128 | 126 |
|
|
0 commit comments