[sqlite3] Fix type of row_factory for Connection and Cursor #15316
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #15308.
row_factory, if notNone, is a callable that receives a Cursor instance and a tuple of row values.sqlite3.Rowitself is such a callable, but claiming that it will be passed as an argument to the row_factory function is wrong, as it does not match documented and actual behavior.Although not necessary (since it's covered by the
Callable[...]), the corrected type hint leavestype[Row]in place as an explicit option to make this connection immediately obvious.See
https://docs.python.org/3.14/library/sqlite3.html#sqlite3.Cursor.row_factory
I'm not sure about PR etiquette on this project, so this is my best effort after reading CONTRIBUTING.md and the contents of
tests/. Happy to make any suggested corrections.Tested with
pre-commit run --all-filesandpython3 tests/runtests.py stdlib/sqlite3. (The latter produces unrelatedstubtesterrors for me, which are the same when running the command on the unmodifiedmainbranch.)Manual test
Use the following Python snippet with valid code that produces a type checker false positive with the faulty stubs, but works with the proposed fix:
Output of the script itself shows a tuple is being passed:
Unpatched false positive:
With fix: