-
Notifications
You must be signed in to change notification settings - Fork 46
FIX: Type annotation for executemany seq_of_parameters to accept Mapping #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| import uuid | ||
| import datetime | ||
| import warnings | ||
| from typing import List, Union, Any, Optional, Tuple, Sequence, TYPE_CHECKING, Iterable | ||
| from typing import List, Mapping, Union, Any, Optional, Tuple, Sequence, TYPE_CHECKING, Iterable | ||
| from mssql_python.constants import ConstantsDDBC as ddbc_sql_const, SQLTypes | ||
| from mssql_python.helpers import check_error, connstr_to_pycore_params | ||
| from mssql_python.logging import logger | ||
|
|
@@ -2063,7 +2063,7 @@ def _compute_column_type(self, column): | |
| return sample_value, None, None | ||
|
|
||
| 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]]] | ||
|
||
| ) -> None: | ||
| """ | ||
| Prepare a database operation and execute it against all parameter sequences. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ Licensed under the MIT license. | |
| Type stubs for mssql_python package - based on actual public API | ||
| """ | ||
|
|
||
| from typing import Any, Dict, List, Optional, Union, Tuple, Sequence, Callable, Iterator | ||
| from typing import Any, Dict, List, Mapping, Optional, Union, Tuple, Sequence, Callable, Iterator | ||
| import datetime | ||
| import logging | ||
| import pyarrow | ||
|
|
@@ -192,7 +192,7 @@ class Cursor: | |
| use_prepare: bool = True, | ||
| 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: ... | ||
|
||
| def fetchone(self) -> Optional[Row]: ... | ||
| def fetchmany(self, size: Optional[int] = None) -> List[Row]: ... | ||
| def fetchall(self) -> List[Row]: ... | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
seq_of_parametersannotation is unnecessarily restrictive by requiring aList[...]. In practice (and per common DB-API usage), callers often pass tuples/other iterables. Consider widening the annotation toSequence[...]orIterable[...](e.g.,Iterable[Sequence[Any]] | Iterable[Mapping[str, Any]], orIterable[Sequence[Any] | Mapping[str, Any]]if mixed batches are supported) so type checking matches the accepted runtime inputs.