Skip to content
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

Improve sqlite3 types #7641

Merged
merged 10 commits into from Apr 16, 2022
Merged

Improve sqlite3 types #7641

merged 10 commits into from Apr 16, 2022

Conversation

JelleZijlstra
Copy link
Member

No description provided.

Read through the code in CPython and made the types more precise
where possible.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member Author

The new errors are correct but possibly too pedantic. I made fetchone() return Any | None, because it can in fact return None: https://github.com/python/cpython/blob/055760ed9e745a3104acbfa8a3b76eb26a72590d/Modules/_sqlite/cursor.c#L829. But often you know that there's at least one row (e.g., because you ran a COUNT query), so I'd be open to changing it back to Any. This is similar to the issues we've had with re.match possibly returning None.

@AlexWaygood
Copy link
Member

The new errors are correct but possibly too pedantic. I made fetchone() return Any | None, because it can in fact return None: https://github.com/python/cpython/blob/055760ed9e745a3104acbfa8a3b76eb26a72590d/Modules/_sqlite/cursor.c#L829. But often you know that there's at least one row (e.g., because you ran a COUNT query), so I'd be open to changing it back to Any. This is similar to the issues we've had with re.match possibly returning None.

If the aim is to get these new stubs in before the next mypy release, maybe it'd be best to change it back to Any for now, and we can revisit it later?

@github-actions

This comment has been minimized.

stdlib/sqlite3/dbapi2.pyi Show resolved Hide resolved
stdlib/sqlite3/dbapi2.pyi Outdated Show resolved Hide resolved
stdlib/sqlite3/dbapi2.pyi Outdated Show resolved Hide resolved
stdlib/sqlite3/dbapi2.pyi Outdated Show resolved Hide resolved
JelleZijlstra and others added 4 commits April 16, 2022 11:04
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

rclip (https://github.com/yurijmikhalevich/rclip)
+ rclip/db.py:70: error: Argument 1 to "update" of "MutableMapping" has incompatible type "NewImage"; expected "SupportsKeysAndGetItem[str, None]"
+ rclip/db.py:70: note:         def __getitem__(self, str) -> None
- rclip/db.py:70: error: Argument 1 to "update" of "MutableMapping" has incompatible type "NewImage"; expected "SupportsKeysAndGetItem[Any, None]"
- rclip/db.py:70: note:         def __getitem__(self, Any) -> None

@JelleZijlstra JelleZijlstra merged commit b0611bc into python:master Apr 16, 2022
@JelleZijlstra JelleZijlstra deleted the sqlite branch April 16, 2022 18:20
altendky added a commit to altendky/typeshed that referenced this pull request Jun 8, 2022
Introduced in python#7641.  Removal discussed at python#8027.
JelleZijlstra pushed a commit that referenced this pull request Jun 11, 2022
Introduced in #7641.  Removal discussed at #8027.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants