19
19
20
20
21
21
if IS_PYDANTIC_V2 :
22
- from pydantic import ConfigDict
22
+ from pydantic import ConfigDict as PydanticModelConfig
23
23
from pydantic_core import PydanticUndefined as PydanticUndefined # noqa
24
24
from pydantic_core import PydanticUndefinedType as PydanticUndefinedType
25
25
else :
26
- from pydantic import BaseConfig # noqa
26
+ from pydantic import BaseConfig as PydanticModelConfig
27
27
from pydantic .fields import ModelField # noqa
28
- from pydantic .fields import Undefined as PydanticUndefined , SHAPE_SINGLETON
28
+ from pydantic .fields import Undefined as PydanticUndefined , UndefinedType as PydanticUndefinedType , SHAPE_SINGLETON # noqa
29
29
from pydantic .typing import resolve_annotations
30
30
31
31
if TYPE_CHECKING :
37
37
InstanceOrType = Union [T , Type [T ]]
38
38
39
39
if IS_PYDANTIC_V2 :
40
- PydanticModelConfig = ConfigDict
41
-
42
- class SQLModelConfig (ConfigDict , total = False ):
40
+ class SQLModelConfig (PydanticModelConfig , total = False ):
43
41
table : Optional [bool ]
44
42
registry : Optional [Any ]
45
43
46
44
else :
47
- PydanticModelConfig = BaseConfig
48
-
49
- class SQLModelConfig (BaseConfig ):
45
+ class SQLModelConfig (PydanticModelConfig ):
50
46
table : Optional [bool ] = None
51
47
registry : Optional [Any ] = None
52
48
@@ -72,7 +68,7 @@ def set_config_value(
72
68
model : InstanceOrType ["SQLModel" ],
73
69
parameter : str ,
74
70
value : Any ,
75
- v1_parameter : str = None ,
71
+ v1_parameter : Optional [ str ] = None ,
76
72
) -> None :
77
73
if IS_PYDANTIC_V2 :
78
74
model .model_config [parameter ] = value # type: ignore
@@ -82,14 +78,14 @@ def set_config_value(
82
78
83
79
def get_model_fields (model : InstanceOrType ["SQLModel" ]) -> Dict [str , "FieldInfo" ]:
84
80
if IS_PYDANTIC_V2 :
85
- return model .model_fields # type: ignore
81
+ return model .model_fields # type: ignore
86
82
else :
87
83
return model .__fields__ # type: ignore
88
84
89
85
90
86
def get_fields_set (model : InstanceOrType ["SQLModel" ]) -> set [str ]:
91
87
if IS_PYDANTIC_V2 :
92
- return model .__pydantic_fields_set__
88
+ return model .__pydantic_fields_set__ # type: ignore
93
89
else :
94
90
return model .__fields_set__ # type: ignore
95
91
@@ -127,10 +123,10 @@ def is_table(class_dict: dict[str, Any]) -> bool:
127
123
config = class_dict .get ("__config__" , {})
128
124
config_table = config .get ("table" , PydanticUndefined )
129
125
if config_table is not PydanticUndefined :
130
- return config_table
126
+ return config_table # type: ignore
131
127
kw_table = class_dict .get ("table" , PydanticUndefined )
132
128
if kw_table is not PydanticUndefined :
133
- return kw_table
129
+ return kw_table # type: ignore
134
130
return False
135
131
136
132
@@ -197,7 +193,7 @@ def set_empty_defaults(annotations: Dict[str, Any], class_dict: Dict[str, Any])
197
193
def is_field_noneable (field : "FieldInfo" ) -> bool :
198
194
if IS_PYDANTIC_V2 :
199
195
if getattr (field , "nullable" , PydanticUndefined ) is not PydanticUndefined :
200
- return field .nullable
196
+ return field .nullable # type: ignore
201
197
if not field .is_required ():
202
198
default = getattr (field , "original_default" , field .default )
203
199
if default is PydanticUndefined :
0 commit comments