|
9 | 9 | Annotated, |
10 | 10 | Any, |
11 | 11 | ForwardRef, |
12 | | - Optional, |
| 12 | + TypeAlias, |
13 | 13 | TypeVar, |
14 | 14 | Union, |
| 15 | + get_args, |
| 16 | + get_origin, |
15 | 17 | ) |
16 | 18 |
|
17 | 19 | from annotated_types import MaxLen |
|
24 | 26 | from pydantic.fields import FieldInfo |
25 | 27 | from pydantic_core import PydanticUndefined as Undefined |
26 | 28 | from pydantic_core import PydanticUndefinedType as PydanticUndefinedType |
27 | | -from typing_extensions import get_args, get_origin |
28 | 29 |
|
29 | 30 | BaseConfig = ConfigDict |
30 | 31 | UndefinedType = PydanticUndefinedType |
|
37 | 38 | UnionType = getattr(types, "UnionType", Union) |
38 | 39 | NoneType = type(None) |
39 | 40 | T = TypeVar("T") |
40 | | -InstanceOrType = Union[T, type[T]] |
| 41 | +InstanceOrType: TypeAlias = T | type[T] |
41 | 42 | _TSQLModel = TypeVar("_TSQLModel", bound="SQLModel") |
42 | 43 |
|
43 | 44 |
|
44 | 45 | class FakeMetadata: |
45 | | - max_length: Optional[int] = None |
46 | | - max_digits: Optional[int] = None |
47 | | - decimal_places: Optional[int] = None |
| 46 | + max_length: int | None = None |
| 47 | + max_digits: int | None = None |
| 48 | + decimal_places: int | None = None |
48 | 49 |
|
49 | 50 |
|
50 | 51 | @dataclass |
@@ -75,8 +76,8 @@ def partial_init() -> Generator[None, None, None]: |
75 | 76 |
|
76 | 77 |
|
77 | 78 | class SQLModelConfig(BaseConfig, total=False): |
78 | | - table: Optional[bool] |
79 | | - registry: Optional[Any] |
| 79 | + table: bool | None |
| 80 | + registry: Any | None |
80 | 81 |
|
81 | 82 |
|
82 | 83 | def get_model_fields(model: InstanceOrType[BaseModel]) -> dict[str, "FieldInfo"]: |
@@ -208,7 +209,7 @@ def sqlmodel_table_construct( |
208 | 209 | *, |
209 | 210 | self_instance: _TSQLModel, |
210 | 211 | values: dict[str, Any], |
211 | | - _fields_set: Union[set[str], None] = None, |
| 212 | + _fields_set: set[str] | None = None, |
212 | 213 | ) -> _TSQLModel: |
213 | 214 | # Copy from Pydantic's BaseModel.construct() |
214 | 215 | # Ref: https://github.com/pydantic/pydantic/blob/v2.5.2/pydantic/main.py#L198 |
@@ -236,7 +237,7 @@ def sqlmodel_table_construct( |
236 | 237 | _fields_set = set(fields_values.keys()) |
237 | 238 | fields_values.update(defaults) |
238 | 239 |
|
239 | | - _extra: Union[dict[str, Any], None] = None |
| 240 | + _extra: dict[str, Any] | None = None |
240 | 241 | if cls.model_config.get("extra") == "allow": |
241 | 242 | _extra = {} |
242 | 243 | for k, v in values.items(): |
@@ -276,10 +277,10 @@ def sqlmodel_validate( |
276 | 277 | cls: type[_TSQLModel], |
277 | 278 | obj: Any, |
278 | 279 | *, |
279 | | - strict: Union[bool, None] = None, |
280 | | - from_attributes: Union[bool, None] = None, |
281 | | - context: Union[dict[str, Any], None] = None, |
282 | | - update: Union[dict[str, Any], None] = None, |
| 280 | + strict: bool | None = None, |
| 281 | + from_attributes: bool | None = None, |
| 282 | + context: dict[str, Any] | None = None, |
| 283 | + update: dict[str, Any] | None = None, |
283 | 284 | ) -> _TSQLModel: |
284 | 285 | if not is_table_model_class(cls): |
285 | 286 | new_obj: _TSQLModel = cls.__new__(cls) |
|
0 commit comments