Skip to content

Type annotation for executemany seq_of_parameters invalid for pyformat style #469

Description

@zacharyeller13

Describe the bug

The type annotation for seq_of_parameters in Cursor.executemany does not appear to be correct for the pyformat style where seq_of_parameters might be a list of dicts/mappings with parameter names as keys.

To reproduce

Using pyright as a typechecker:

query = "..."
params: list[dict[str, Any]] = [{"param1": "foo", "param2": "bar"}]
cursor.executemany(query, params) # pyright error: "Argument of type "list[dict[str, Any]]" cannot be assigned to parameter "seq_of_parameters" of type "List[Sequence[Any]]" in function "executemany""
from collections.abc import Sequence
params = {"foo": "bar"}
print(isinstance(params, Sequence)) # False

Expected behavior

executemany should accept any seq_of_params that matches the shape [{"key": <value>}]. Something like List[Sequence[Any]] | List[Mapping[str, Any]] or List[Sequence[Any]] | List[Dict[str, Any]]

Further technical details

Python version: 3.12.12
Operating system: MacOS 26.2
Pyright version: 1.1.408

Additional context

Though dict does implement the __getitem__ and __len__ methods of the Sequence protocol, it is not technically a Sequence (see PySequence_Check as well as the isinstance check shown above)

Not that big of a deal in the grand scheme of things but would be nice to avoid having to put "#pyright: ignore[reportArgumentType]" in calling code. Happy to submit a PR for this too, but wanted to submit the issue first.

Metadata

Metadata

Assignees

Labels

FIXEDarea: api-compliancePython API behavior and typing: DB-API 2.0, exceptions, type stubs, new APIs.bugSomething isn't workingcommunityPR or Issue raised by community membersinADO

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions