1919
2020
2121if IS_PYDANTIC_V2 :
22- from pydantic import ConfigDict
22+ from pydantic import ConfigDict as PydanticModelConfig
2323 from pydantic_core import PydanticUndefined as PydanticUndefined # noqa
2424 from pydantic_core import PydanticUndefinedType as PydanticUndefinedType
2525else :
26- from pydantic import BaseConfig # noqa
26+ from pydantic import BaseConfig as PydanticModelConfig
2727 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
2929 from pydantic .typing import resolve_annotations
3030
3131if TYPE_CHECKING :
3737InstanceOrType = Union [T , Type [T ]]
3838
3939if IS_PYDANTIC_V2 :
40- PydanticModelConfig = ConfigDict
41-
42- class SQLModelConfig (ConfigDict , total = False ):
40+ class SQLModelConfig (PydanticModelConfig , total = False ):
4341 table : Optional [bool ]
4442 registry : Optional [Any ]
4543
4644else :
47- PydanticModelConfig = BaseConfig
48-
49- class SQLModelConfig (BaseConfig ):
45+ class SQLModelConfig (PydanticModelConfig ):
5046 table : Optional [bool ] = None
5147 registry : Optional [Any ] = None
5248
@@ -72,7 +68,7 @@ def set_config_value(
7268 model : InstanceOrType ["SQLModel" ],
7369 parameter : str ,
7470 value : Any ,
75- v1_parameter : str = None ,
71+ v1_parameter : Optional [ str ] = None ,
7672) -> None :
7773 if IS_PYDANTIC_V2 :
7874 model .model_config [parameter ] = value # type: ignore
@@ -82,14 +78,14 @@ def set_config_value(
8278
8379def get_model_fields (model : InstanceOrType ["SQLModel" ]) -> Dict [str , "FieldInfo" ]:
8480 if IS_PYDANTIC_V2 :
85- return model .model_fields # type: ignore
81+ return model .model_fields # type: ignore
8682 else :
8783 return model .__fields__ # type: ignore
8884
8985
9086def get_fields_set (model : InstanceOrType ["SQLModel" ]) -> set [str ]:
9187 if IS_PYDANTIC_V2 :
92- return model .__pydantic_fields_set__
88+ return model .__pydantic_fields_set__ # type: ignore
9389 else :
9490 return model .__fields_set__ # type: ignore
9591
@@ -127,10 +123,10 @@ def is_table(class_dict: dict[str, Any]) -> bool:
127123 config = class_dict .get ("__config__" , {})
128124 config_table = config .get ("table" , PydanticUndefined )
129125 if config_table is not PydanticUndefined :
130- return config_table
126+ return config_table # type: ignore
131127 kw_table = class_dict .get ("table" , PydanticUndefined )
132128 if kw_table is not PydanticUndefined :
133- return kw_table
129+ return kw_table # type: ignore
134130 return False
135131
136132
@@ -197,7 +193,7 @@ def set_empty_defaults(annotations: Dict[str, Any], class_dict: Dict[str, Any])
197193def is_field_noneable (field : "FieldInfo" ) -> bool :
198194 if IS_PYDANTIC_V2 :
199195 if getattr (field , "nullable" , PydanticUndefined ) is not PydanticUndefined :
200- return field .nullable
196+ return field .nullable # type: ignore
201197 if not field .is_required ():
202198 default = getattr (field , "original_default" , field .default )
203199 if default is PydanticUndefined :
0 commit comments