Skip to content

Commit af23ba8

Browse files
committed
🏷️ Adjust type annotation for Field.sa_type to support instantiated SQLAlchemy types
1 parent 6c0410e commit af23ba8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎sqlmodel/main.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
from sqlalchemy.orm.attributes import set_attribute
5151
from sqlalchemy.orm.decl_api import DeclarativeMeta
5252
from sqlalchemy.orm.instrumentation import is_instrumented
53-
from sqlalchemy.sql.schema import MetaData
53+
from sqlalchemy.sql.schema import MetaData, SchemaEventTarget
5454
from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid
55+
from sqlalchemy.types import TypeEngine
5556
from typing_extensions import Literal, TypeAlias, deprecated, get_origin
5657

5758
from ._compat import ( # type: ignore[attr-defined]
@@ -96,6 +97,7 @@
9697
Mapping[int, Union["IncEx", bool]],
9798
Mapping[str, Union["IncEx", bool]],
9899
]
100+
SaType: TypeAlias = Union[TypeEngine[Any], Type[TypeEngine[Any]], SchemaEventTarget]
99101
OnDeleteType = Literal["CASCADE", "SET NULL", "RESTRICT"]
100102

101103

@@ -245,7 +247,7 @@ def Field(
245247
unique: Union[bool, UndefinedType] = Undefined,
246248
nullable: Union[bool, UndefinedType] = Undefined,
247249
index: Union[bool, UndefinedType] = Undefined,
248-
sa_type: Union[Type[Any], UndefinedType] = Undefined,
250+
sa_type: Union[SaType, UndefinedType] = Undefined,
249251
sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined,
250252
sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined,
251253
schema_extra: Optional[Dict[str, Any]] = None,
@@ -291,7 +293,7 @@ def Field(
291293
unique: Union[bool, UndefinedType] = Undefined,
292294
nullable: Union[bool, UndefinedType] = Undefined,
293295
index: Union[bool, UndefinedType] = Undefined,
294-
sa_type: Union[Type[Any], UndefinedType] = Undefined,
296+
sa_type: Union[SaType, UndefinedType] = Undefined,
295297
sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined,
296298
sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined,
297299
schema_extra: Optional[Dict[str, Any]] = None,
@@ -380,7 +382,7 @@ def Field(
380382
unique: Union[bool, UndefinedType] = Undefined,
381383
nullable: Union[bool, UndefinedType] = Undefined,
382384
index: Union[bool, UndefinedType] = Undefined,
383-
sa_type: Union[Type[Any], UndefinedType] = Undefined,
385+
sa_type: Union[SaType, UndefinedType] = Undefined,
384386
sa_column: Union[Column, UndefinedType] = Undefined, # type: ignore
385387
sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined,
386388
sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined,

0 commit comments

Comments
 (0)