Skip to content

Commit a56d060

Browse files
committed
🎨 Fix types for Python 3.10 for _compat
1 parent 24dafbc commit a56d060

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

sqlmodel/_compat.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
Annotated,
1010
Any,
1111
ForwardRef,
12-
Optional,
12+
TypeAlias,
1313
TypeVar,
1414
Union,
15+
get_args,
16+
get_origin,
1517
)
1618

1719
from annotated_types import MaxLen
@@ -24,7 +26,6 @@
2426
from pydantic.fields import FieldInfo
2527
from pydantic_core import PydanticUndefined as Undefined
2628
from pydantic_core import PydanticUndefinedType as PydanticUndefinedType
27-
from typing_extensions import get_args, get_origin
2829

2930
BaseConfig = ConfigDict
3031
UndefinedType = PydanticUndefinedType
@@ -37,14 +38,14 @@
3738
UnionType = getattr(types, "UnionType", Union)
3839
NoneType = type(None)
3940
T = TypeVar("T")
40-
InstanceOrType = Union[T, type[T]]
41+
InstanceOrType: TypeAlias = T | type[T]
4142
_TSQLModel = TypeVar("_TSQLModel", bound="SQLModel")
4243

4344

4445
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
4849

4950

5051
@dataclass
@@ -75,8 +76,8 @@ def partial_init() -> Generator[None, None, None]:
7576

7677

7778
class SQLModelConfig(BaseConfig, total=False):
78-
table: Optional[bool]
79-
registry: Optional[Any]
79+
table: bool | None
80+
registry: Any | None
8081

8182

8283
def get_model_fields(model: InstanceOrType[BaseModel]) -> dict[str, "FieldInfo"]:
@@ -208,7 +209,7 @@ def sqlmodel_table_construct(
208209
*,
209210
self_instance: _TSQLModel,
210211
values: dict[str, Any],
211-
_fields_set: Union[set[str], None] = None,
212+
_fields_set: set[str] | None = None,
212213
) -> _TSQLModel:
213214
# Copy from Pydantic's BaseModel.construct()
214215
# Ref: https://github.com/pydantic/pydantic/blob/v2.5.2/pydantic/main.py#L198
@@ -236,7 +237,7 @@ def sqlmodel_table_construct(
236237
_fields_set = set(fields_values.keys())
237238
fields_values.update(defaults)
238239

239-
_extra: Union[dict[str, Any], None] = None
240+
_extra: dict[str, Any] | None = None
240241
if cls.model_config.get("extra") == "allow":
241242
_extra = {}
242243
for k, v in values.items():
@@ -276,10 +277,10 @@ def sqlmodel_validate(
276277
cls: type[_TSQLModel],
277278
obj: Any,
278279
*,
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,
283284
) -> _TSQLModel:
284285
if not is_table_model_class(cls):
285286
new_obj: _TSQLModel = cls.__new__(cls)

0 commit comments

Comments
 (0)