Make Values().data input covariant with Sequence

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: 7800f0d631

Change-Id: If631455d049b2308ec42602b72a60a5ede35fa32
This commit is contained in:
Iuri de Silvio
2023-10-12 08:25:40 -04:00
committed by Mike Bayer
parent a342b3d503
commit 6f710b393a
3 changed files with 16 additions and 5 deletions
+7
View File
@@ -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.
+3 -3
View 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__()
@@ -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"))