--- /dev/null
+.. change::
+ :tags: bug, typing
+ :tickets: 9376
+
+ Improved typing for the mapping passed to :meth:`.UpdateBase.values` to be
+ more open-ended about collection type, by indicating read-only ``Mapping``
+ instead of writeable ``Dict`` which would error out on too limited of a key
+ type.
from typing import Any
from typing import Callable
from typing import Dict
+from typing import Mapping
from typing import Set
from typing import Tuple
from typing import Type
"""
+_DMLKey = TypeVar("_DMLKey", bound=_DMLColumnArgument)
+_DMLColumnKeyMapping = Mapping[_DMLKey, Any]
+
_DDLColumnArgument = Union[str, "Column[Any]", roles.DDLConstraintColumnRole]
"""DDL column.
from ._typing import _ColumnExpressionArgument
from ._typing import _ColumnsClauseArgument
from ._typing import _DMLColumnArgument
+ from ._typing import _DMLColumnKeyMapping
from ._typing import _DMLTableArgument
from ._typing import _T0 # noqa
from ._typing import _T1 # noqa
def values(
self,
*args: Union[
- Dict[_DMLColumnArgument, Any],
+ _DMLColumnKeyMapping[Any],
Sequence[Any],
],
**kwargs: Any,
--- /dev/null
+from __future__ import annotations
+
+from typing import Any
+from typing import Dict
+
+from sqlalchemy import Column
+from sqlalchemy import insert
+from sqlalchemy.orm import DeclarativeBase
+from sqlalchemy.orm import Mapped
+from sqlalchemy.orm import mapped_column
+
+
+class Base(DeclarativeBase):
+ pass
+
+
+class User(Base):
+ __tablename__ = "user"
+
+ id: Mapped[int] = mapped_column(primary_key=True)
+ name: Mapped[str]
+ data: Mapped[str]
+
+
+# test #9376
+d1: dict[str, Any] = {}
+stmt1 = insert(User).values(d1)
+
+
+d2: Dict[str, Any] = {}
+stmt2 = insert(User).values(d2)
+
+
+d3: Dict[Column[str], Any] = {}
+stmt3 = insert(User).values(d3)