Now `Column(type_=ARRAY(Integer)` is inferred as `Column[Sequence[int]]` instead as `Column[Sequence[Any]]` previously. This only works with the `type_` argument to Column, but that's not new.
This follows from a suggestion at
https://github.com/sqlalchemy/sqlalchemy/pull/12386#issuecomment-
2694056069.
Related to #6810.
Closes: #12443
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12443
Pull-request-sha:
2fff4e89cd0b72d9444ce3f3d845b152770fc55d
Change-Id: I87b828fd82d10fbf157141db3c31f0ec8149caad
return self
-class ARRAY(sqltypes.ARRAY):
+class ARRAY(sqltypes.ARRAY[_T]):
"""PostgreSQL ARRAY type.
The :class:`_postgresql.ARRAY` type is constructed in the same way
def __init__(
self,
- item_type: _TypeEngineArgument[typing_Any],
+ item_type: _TypeEngineArgument[_T],
as_tuple: bool = False,
dimensions: Optional[int] = None,
zero_indexes: bool = False,
self.dimensions = dimensions
self.zero_indexes = zero_indexes
- class Comparator(sqltypes.ARRAY.Comparator):
+ class Comparator(sqltypes.ARRAY.Comparator[_T]):
"""Define comparison operations for :class:`_types.ARRAY`.
Note that these operations are in addition to those provided
def _against_native_enum(self) -> bool:
return (
isinstance(self.item_type, sqltypes.Enum)
- and self.item_type.native_enum
+ and self.item_type.native_enum # type: ignore[attr-defined]
)
def literal_processor(
class ARRAY(
- SchemaEventTarget, Indexable, Concatenable, TypeEngine[Sequence[Any]]
+ SchemaEventTarget, Indexable, Concatenable, TypeEngine[Sequence[_T]]
):
"""Represent a SQL Array type.
def __init__(
self,
- item_type: _TypeEngineArgument[Any],
+ item_type: _TypeEngineArgument[_T],
as_tuple: bool = False,
dimensions: Optional[int] = None,
zero_indexes: bool = False,
self.zero_indexes = zero_indexes
class Comparator(
- Indexable.Comparator[Sequence[Any]],
- Concatenable.Comparator[Sequence[Any]],
+ Indexable.Comparator[Sequence[_T]],
+ Concatenable.Comparator[Sequence[_T]],
):
"""Define comparison operations for :class:`_types.ARRAY`.
__slots__ = ()
- type: ARRAY
+ type: ARRAY[_T]
@overload
def _setup_getitem(
# EXPECTED_MYPY: Cannot infer type argument 1 of "array"
array([0], type_=Text)
+
+# EXPECTED_TYPE: ARRAY[str]
+reveal_type(ARRAY(Text))
+
+# EXPECTED_TYPE: Column[Sequence[int]]
+reveal_type(Column(type_=ARRAY(Integer)))