| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…oft#572) The 1.6.0 signature seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]] regressed type-checking for callers passing a more precise list type such as list[tuple[str, str, str, str, int, str]]. Because typing.List is invariant, mypy rejects it with: error: Argument 2 to "executemany" of "Cursor" has incompatible type "list[tuple[...]]"; expected "list[Sequence[Any]] | list[Mapping[str, Any]]" [arg-type] note: "list" is invariant -- see ... note: Consider using "Sequence" instead, which is covariant In 1.5.0 the parameter was a single arm (List[Sequence[Any]]) which mypy accepted via the gradual-typing escape hatch on Any; the union introduced in 1.6.0 forces mypy to pick a matching arm and invariance kicks in, breaking previously valid call sites. Switch to the covariant Sequence outer container on both the public Cursor.executemany and the internal _transpose_rowwise_to_columnwise helper: seq_of_parameters: Union[ Sequence[Sequence[Any]], Sequence[Mapping[str, Any]], ] This: - accepts list[tuple[...]], list[list[...]], tuple of tuples, etc.; - matches PEP 249 ("sequence of sequences"); - aligns with pyodbc's typing; - keeps the 1.6.0 dict/pyformat support intact. Runtime behaviour is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
This PR addresses the Cursor.executemany typing regression by changing the outer parameter container from invariant List to covariant Sequence.
Changes:
mssql_python/cursor.py:2139
seq_of_parameters: Union[Sequence[Sequence[Any]], Sequence[Mapping[str, Any]]],
mssql_python/cursor.py:2139
seq_of_parameters: Union[Sequence[Sequence[Any]], Sequence[Mapping[str, Any]]],
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 59.7%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 76.1%
mssql_python.row.py: 76.9%
mssql_python.__init__.py: 77.3%
mssql_python.pybind.connection.connection.cpp: 77.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.logging.py: 85.5%
mssql_python.connection.py: 85.6%🔗 Quick Links
|
Sorry, something went wrong.
Two follow-ups from the Copilot PR review on microsoft#586: 1. mssql_python/mssql_python.pyi still carried the old invariant signature seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]] Sync it to the covariant Sequence form to match cursor.py and prevent a silent regression if the stub is ever relocated to __init__.pyi (where mypy would actually consume it). 2. _transpose_rowwise_to_columnwise is only ever called with already-converted positional rows (pyformat-to-qmark conversion happens upstream in executemany before transposition). Advertising it as accepting Mapping rows is misleading - the transpose loop would yield mapping keys, not values. Narrow its annotation to Sequence[Sequence[Any]] only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
[AB#43993](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/43993) ### Summary Release mssql-python v1.8.0. ### Enhancements - **ActiveDirectoryMSI Support for Bulk Copy** (#573) - **Row String-Key Indexing** (#589) - **Bundled ODBC Driver Upgrade** from 18.5.1.1 to 18.6.2.1 (#569) ### Bug Fixes - **Deferred Connect-Attribute Use-After-Free** (#596) - Fixes #594, #597 - **Connection String Parsed Multiple Times in Auth Path** (#590) - Fixes #580 - **executemany Type Annotation Regression** (#586) - Fixes #572 ### Version Bump - `__version__` → 1.8.0 in `__init__.py` and `setup.py` - `PyPI_Description.md` updated with v1.8.0 release notes
| Back | FazBrowse Home | New Git URL |
Work Item / Issue Reference
Summary
Fixes the typing regression reported in #572.
In v1.5.0, the second parameter of Cursor.executemany was typed as:
In v1.6.0 it was widened to also accept pyformat / dict-style parameters:
That widening is functionally correct, but it surfaced a long-standing typing problem. typing.List is invariant in its type parameter, so a perfectly valid list[tuple[str, str, str, str, int, str]] argument no longer matches either arm of the Union, and mypy rejects previously valid call sites:
In v1.5.0 the single-arm List[Sequence[Any]] slipped through mypy's gradual-typing escape hatch on Any. The Union in v1.6.0 forces mypy to commit to one arm, invariance kicks in, and call sites that worked for years break.
The fix
Switch the outer container to the covariant Sequence, on both the public Cursor.executemany and the internal _transpose_rowwise_to_columnwise helper:
This:
Verification
Reproducer derived from the issue: