diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/array.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/array.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py index 74643c4d9..7eec7b86f 100644 --- a/lib/sqlalchemy/dialects/postgresql/array.py +++ b/lib/sqlalchemy/dialects/postgresql/array.py @@ -5,14 +5,19 @@ # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php +from __future__ import annotations + import re +from typing import Any +from typing import TypeVar from ... import types as sqltypes from ... import util -from ...sql import coercions from ...sql import expression from ...sql import operators -from ...sql import roles + + +_T = TypeVar("_T", bound=Any) def Any(other, arrexpr, operator=operators.eq): @@ -33,7 +38,7 @@ def All(other, arrexpr, operator=operators.eq): return arrexpr.all(other, operator) -class array(expression.ClauseList, expression.ColumnElement): +class array(expression.ExpressionClauseList[_T]): """A PostgreSQL ARRAY literal. @@ -90,16 +95,19 @@ class array(expression.ClauseList, expression.ColumnElement): inherit_cache = True def __init__(self, clauses, **kw): - clauses = [ - coercions.expect(roles.ExpressionElementRole, c) for c in clauses - ] - - self._type_tuple = [arg.type for arg in clauses] - main_type = kw.pop( - "type_", - self._type_tuple[0] if self._type_tuple else sqltypes.NULLTYPE, + + type_arg = kw.pop("type_", None) + super(array, self).__init__(operators.comma_op, *clauses, **kw) + + self._type_tuple = [arg.type for arg in self.clauses] + + main_type = ( + type_arg + if type_arg is not None + else self._type_tuple[0] + if self._type_tuple + else sqltypes.NULLTYPE ) - super(array, self).__init__(*clauses, **kw) if isinstance(main_type, ARRAY): self.type = ARRAY( |