Skip to content

Invariant Type on Cursor.executemany #572

Description

Describe the bug

The 2nd argument of Cursor.executemany is typed as seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]] in version 1.6.0. This causes type errors on more precise arguments:

error: Argument 2 to "executemany" of "Cursor" has incompatible type "list[tuple[str, str, str, str, int, str]]"; expected "list[Sequence[Any]] | list[Mapping[str, Any]]"  [arg-type]
"list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
note: Consider using "Sequence" instead, which is covariant

This is a regression from version 1.5.0, where the type seq_of_parameters: List[Sequence[Any]] didn't cause that problem. Suggestion: just use sequence instead of list and add linting for that.

To reproduce

curs.executemany(sql, [("a", 1)])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: api-compliancePython API behavior and typing: DB-API 2.0, exceptions, type stubs, new APIs.bugSomething isn't workingregressionTracks issues which are regressionstriage doneIssues that are triaged by dev team and are in investigation.under development

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions