]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Make Values().data input covariant with Sequence
authorIuri de Silvio <iuri.desilvio@channable.com>
Thu, 12 Oct 2023 12:25:40 +0000 (08:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Oct 2023 14:08:24 +0000 (10:08 -0400)
Fixed typing issue where the argument list passed to :class:`.Values` was
too-restrictively tied to ``List`` rather than ``Sequence``.  Pull request
courtesy Iuri de Silvio.

Fixes: #10451
Closes: #10452
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10452
Pull-request-sha: 7800f0d631f75b716b8870755e5d0a3fbe950277

Change-Id: If631455d049b2308ec42602b72a60a5ede35fa32

doc/build/changelog/unreleased_20/10451.rst [new file with mode: 0644]
lib/sqlalchemy/sql/selectable.py
test/typing/plain_files/sql/lowercase_objects.py

diff --git a/doc/build/changelog/unreleased_20/10451.rst b/doc/build/changelog/unreleased_20/10451.rst
new file mode 100644 (file)
index 0000000..12f1a90
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, typing
+    :tickets: 10451
+
+    Fixed typing issue where the argument list passed to :class:`.Values` was
+    too-restrictively tied to ``List`` rather than ``Sequence``.  Pull request
+    courtesy Iuri de Silvio.
index debeb8bb87707cced42539e391b7d559739f8695..91b939e0af50928b099f6b65a184ebea96fb3f34 100644 (file)
@@ -3149,7 +3149,7 @@ class Values(roles.InElementRole, Generative, LateralFromClause):
 
     __visit_name__ = "values"
 
-    _data: Tuple[List[Tuple[Any, ...]], ...] = ()
+    _data: Tuple[Sequence[Tuple[Any, ...]], ...] = ()
 
     _unnamed: bool
     _traverse_internals: _TraverseInternalsType = [
@@ -3233,7 +3233,7 @@ class Values(roles.InElementRole, Generative, LateralFromClause):
         return self
 
     @_generative
-    def data(self, values: List[Tuple[Any, ...]]) -> Self:
+    def data(self, values: Sequence[Tuple[Any, ...]]) -> Self:
         """Return a new :class:`_expression.Values` construct,
         adding the given data to the data list.
 
@@ -3300,7 +3300,7 @@ class ScalarValues(roles.InElementRole, GroupedElement, ColumnElement[Any]):
     def __init__(
         self,
         columns: Sequence[ColumnClause[Any]],
-        data: Tuple[List[Tuple[Any, ...]], ...],
+        data: Tuple[Sequence[Tuple[Any, ...]], ...],
         literal_binds: bool,
     ):
         super().__init__()
index ab26d7ede37f80f98eff27eb9e020e2c145ec2a9..21d9a4595a554578cd568aa5ae3ed2e5e448a2bb 100644 (file)
@@ -8,9 +8,13 @@ Book = sa.table(
 Book.append_column(sa.column("other"))
 Book.corresponding_column(Book.c.id)
 
-value_expr = sa.values(
+values = sa.values(
     sa.column("id", sa.Integer), sa.column("name", sa.String), name="my_values"
-).data([(1, "name1"), (2, "name2"), (3, "name3")])
+)
+value_expr = values.data([(1, "name1"), (2, "name2"), (3, "name3")])
+
+data: list[tuple[int, str]] = [(1, "name1"), (2, "name2"), (3, "name3")]
+value_expr2 = values.data(data)
 
 sa.select(Book)
 sa.select(sa.literal_column("42"), sa.column("foo")).select_from(sa.table("t"))