Skip to content

Commit 7870b7e

Browse files
authored
Allow with_variant to take TypeEngine instance like Column. (#245)
Fixes Fixes: #244
1 parent dd0e6cf commit 7870b7e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

sqlalchemy-stubs/sql/type_api.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class TypeEngine(Traversible, Generic[_T]):
9696
@property
9797
def python_type(self) -> Type[_T]: ...
9898
def with_variant(
99-
self, type_: Type[TypeEngine[_U]], dialect_name: str
99+
self, type_: Union[Type[TypeEngine[_U]], TypeEngine[_U]], dialect_name: str
100100
) -> Variant[_U]: ...
101101
def as_generic(self, allow_nulltype: bool = ...) -> TypeEngine[Any]: ...
102102
def dialect_impl(self, dialect: Dialect) -> Type[Any]: ...
@@ -177,7 +177,7 @@ class Variant(TypeDecorator[_T]):
177177
) -> Union[_VT, TypeEngine[Any]]: ...
178178
def load_dialect_impl(self, dialect: Dialect) -> TypeEngine[Any]: ...
179179
def with_variant(
180-
self, type_: Type[TypeEngine[_U]], dialect_name: str
180+
self, type_: Union[Type[TypeEngine[_U]], TypeEngine[_U]], dialect_name: str
181181
) -> Variant[_U]: ...
182182
@property
183183
def comparator_factory(self) -> Type[Any]: ... # type: ignore[override]

test/files/column_arguments2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,11 @@
8080
# These seems supported now
8181
Column(Integer, ForeignKey("a.id"), type_=String)
8282
Column("name", ForeignKey("a.id"), name="String")
83+
84+
85+
# TypeEngine.with_variant should accept both a TypeEngine instance and the Concrete Type
86+
Integer().with_variant(Integer, "mysql")
87+
Integer().with_variant(Integer(), "mysql")
88+
# Also test Variant.with_variant
89+
Integer().with_variant(Integer, "mysql").with_variant(Integer, "mysql")
90+
Integer().with_variant(Integer, "mysql").with_variant(Integer(), "mysql")

0 commit comments

Comments
 (0)