Skip to content

FIX: Type annotation for executemany seq_of_parameters to accept Mapping#525

Open
bewithgaurav wants to merge 1 commit intomainfrom
bewithgaurav/fix-executemany-type-annotation
Open

FIX: Type annotation for executemany seq_of_parameters to accept Mapping#525
bewithgaurav wants to merge 1 commit intomainfrom
bewithgaurav/fix-executemany-type-annotation

Conversation

@bewithgaurav
Copy link
Copy Markdown
Collaborator

Work Item / Issue Reference

GitHub Issue: #469


Summary

This pull request updates the executemany method in the Cursor class to support both positional and named parameter sequences, improving compatibility with different parameter formats. The changes also update type hints and type stubs to reflect this enhancement.

Type hint and API improvements:

  • Updated the type hint for the executemany method in cursor.py to accept both lists of sequences (for positional parameters) and lists of mappings (for named parameters), allowing for greater flexibility in how parameters are passed.
  • Added Mapping to the imports from typing in both cursor.py and mssql_python.pyi to support the new type hints. [1] [2]
  • Updated the type stub for the executemany method in mssql_python.pyi to match the new accepted parameter types, ensuring type checkers and IDEs recognize the expanded API.

The type annotation for seq_of_parameters in Cursor.executemany did not
accept List[Mapping[str, Any]], which is valid for pyformat-style
parameters. Updated both cursor.py and mssql_python.pyi to use
Union[List[Sequence[Any]], List[Mapping[str, Any]]].

Fixes #469
Copilot AI review requested due to automatic review settings April 15, 2026 09:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Cursor.executemany type annotations/stubs to accept named-parameter batches (mappings) in addition to positional-parameter batches (sequences), aligning the public API typing with broader parameter formats (GitHub Issue #469).

Changes:

  • Expanded executemany parameter typing to allow Mapping[str, Any] batches alongside Sequence[Any] batches.
  • Added Mapping import to both runtime implementation and .pyi stub to support the new type hints.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
mssql_python/mssql_python.pyi Updates the public type stub for Cursor.executemany to accept mapping-based parameter batches.
mssql_python/cursor.py Updates the runtime type annotation for Cursor.executemany to accept mapping-based parameter batches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-statements
self, operation: str, seq_of_parameters: List[Sequence[Any]]
self, operation: str, seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]]
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seq_of_parameters annotation is unnecessarily restrictive by requiring a List[...]. In practice (and per common DB-API usage), callers often pass tuples/other iterables. Consider widening the annotation to Sequence[...] or Iterable[...] (e.g., Iterable[Sequence[Any]] | Iterable[Mapping[str, Any]], or Iterable[Sequence[Any] | Mapping[str, Any]] if mixed batches are supported) so type checking matches the accepted runtime inputs.

Copilot uses AI. Check for mistakes.
reset_cursor: bool = True,
) -> "Cursor": ...
def executemany(self, operation: str, seq_of_parameters: List[Sequence[Any]]) -> None: ...
def executemany(self, operation: str, seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]]) -> None: ...
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the runtime annotation: the stub currently forces List[...], which rejects valid inputs like tuples or other sequence/iterable types in type checkers. Please widen the stub to Sequence[...] or Iterable[...] to reflect typical executemany usage and keep typing ergonomic for callers.

Copilot uses AI. Check for mistakes.

def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-statements
self, operation: str, seq_of_parameters: List[Sequence[Any]]
self, operation: str, seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]]
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expanded executemany type is getting harder to read and now must be duplicated in both cursor.py and mssql_python.pyi. To reduce repetition and make future changes less error-prone, consider introducing a well-named type alias (e.g., ExecutemanyParams) and using it in the signature (and in the stub if feasible).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: small Minimal code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants