From af23ba8bc86cc16931fe88afd5a945e4a34b3ca1 Mon Sep 17 00:00:00 2001 From: diachkow Date: Mon, 21 Apr 2025 10:11:09 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20Adjust=20type=20annotat?= =?UTF-8?q?ion=20for=20Field.sa=5Ftype=20to=20support=20instantiated=20SQL?= =?UTF-8?q?Alchemy=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlmodel/main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 45a41997fe..fb0de8a96a 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -50,8 +50,9 @@ from sqlalchemy.orm.attributes import set_attribute from sqlalchemy.orm.decl_api import DeclarativeMeta from sqlalchemy.orm.instrumentation import is_instrumented -from sqlalchemy.sql.schema import MetaData +from sqlalchemy.sql.schema import MetaData, SchemaEventTarget from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid +from sqlalchemy.types import TypeEngine from typing_extensions import Literal, TypeAlias, deprecated, get_origin from ._compat import ( # type: ignore[attr-defined] @@ -96,6 +97,7 @@ Mapping[int, Union["IncEx", bool]], Mapping[str, Union["IncEx", bool]], ] +SaType: TypeAlias = Union[TypeEngine[Any], Type[TypeEngine[Any]], SchemaEventTarget] OnDeleteType = Literal["CASCADE", "SET NULL", "RESTRICT"] @@ -245,7 +247,7 @@ def Field( unique: Union[bool, UndefinedType] = Undefined, nullable: Union[bool, UndefinedType] = Undefined, index: Union[bool, UndefinedType] = Undefined, - sa_type: Union[Type[Any], UndefinedType] = Undefined, + sa_type: Union[SaType, UndefinedType] = Undefined, sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined, sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined, schema_extra: Optional[Dict[str, Any]] = None, @@ -291,7 +293,7 @@ def Field( unique: Union[bool, UndefinedType] = Undefined, nullable: Union[bool, UndefinedType] = Undefined, index: Union[bool, UndefinedType] = Undefined, - sa_type: Union[Type[Any], UndefinedType] = Undefined, + sa_type: Union[SaType, UndefinedType] = Undefined, sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined, sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined, schema_extra: Optional[Dict[str, Any]] = None, @@ -380,7 +382,7 @@ def Field( unique: Union[bool, UndefinedType] = Undefined, nullable: Union[bool, UndefinedType] = Undefined, index: Union[bool, UndefinedType] = Undefined, - sa_type: Union[Type[Any], UndefinedType] = Undefined, + sa_type: Union[SaType, UndefinedType] = Undefined, sa_column: Union[Column, UndefinedType] = Undefined, # type: ignore sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined, sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined,