From 4f87f4d9265adf826bd10b3b764405c3b871b5d8 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Mon, 1 Dec 2025 05:43:18 -0500 Subject: [PATCH] Type postgresql.ExcludeConstraint() Related to #6810. Closes: #13011 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13011 Pull-request-sha: 4a212cad1b231629ae4e3d6866c9603662a197a2 Change-Id: If5d91e06b6c0afc11adc02bb0c0d5ce97e53203c --- lib/sqlalchemy/dialects/postgresql/ext.py | 6 +++++- test/typing/plain_files/dialects/postgresql/pg_stuff.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index d251c11d6c..a33bfd76f5 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -13,6 +13,7 @@ from typing import List from typing import Optional from typing import overload from typing import Sequence +from typing import Tuple from typing import TYPE_CHECKING from typing import TypeVar @@ -32,6 +33,7 @@ from ...sql.visitors import InternalTraversal if TYPE_CHECKING: from ...sql._typing import _ColumnExpressionArgument + from ...sql._typing import _DDLColumnArgument from ...sql.elements import ClauseElement from ...sql.elements import ColumnElement from ...sql.operators import OperatorType @@ -158,7 +160,9 @@ class ExcludeConstraint(ColumnCollectionConstraint): ":class:`.ExcludeConstraint`", ":paramref:`.ExcludeConstraint.where`", ) - def __init__(self, *elements, **kw): + def __init__( + self, *elements: Tuple[_DDLColumnArgument, str], **kw: Any + ) -> None: r""" Create an :class:`.ExcludeConstraint` object. diff --git a/test/typing/plain_files/dialects/postgresql/pg_stuff.py b/test/typing/plain_files/dialects/postgresql/pg_stuff.py index ec99ec1b0c..1499251103 100644 --- a/test/typing/plain_files/dialects/postgresql/pg_stuff.py +++ b/test/typing/plain_files/dialects/postgresql/pg_stuff.py @@ -19,6 +19,7 @@ from sqlalchemy.dialects.postgresql import aggregate_order_by from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.dialects.postgresql import array from sqlalchemy.dialects.postgresql import DATERANGE +from sqlalchemy.dialects.postgresql import ExcludeConstraint from sqlalchemy.dialects.postgresql import insert from sqlalchemy.dialects.postgresql import INT4RANGE from sqlalchemy.dialects.postgresql import INT8MULTIRANGE @@ -55,6 +56,8 @@ class Test(Base): ident_str: Mapped[str] = mapped_column(UUID(as_uuid=False)) + __table_args__ = (ExcludeConstraint((Column("ident_str"), "=")),) + elem = func.jsonb_array_elements(Test.data, type_=JSONB).column_valued("elem") -- 2.47.3