Skip to content

Sync typeshed#21738

Open
cdce8p wants to merge 12 commits into
python:masterfrom
cdce8p:sync-typeshed
Open

Sync typeshed#21738
cdce8p wants to merge 12 commits into
python:masterfrom
cdce8p:sync-typeshed

Conversation

@cdce8p

@cdce8p cdce8p commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Source commit:
python/typeshed@c6d1070

cdce8p and others added 12 commits July 16, 2026 11:45
This is allegedly causing large performance problems, see 13821

typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing
to undo. Patching this in typeshed also feels weird, since there's a
more general soundness issue. If a typevar has a bound or constraint, we
might not want to solve it to a Literal.

If we can confirm the performance regression or fix the unsoundness
within mypy, I might pursue upstreaming this in typeshed.

(Reminder: add this to the sync_typeshed script once merged)
The plugin provides superior type checking:
python#13987 (comment)
A manual cherry-pick of e437cdf.
@github-actions

Copy link
Copy Markdown
Contributor

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

urllib3 (https://github.com/urllib3/urllib3)
+ test/contrib/test_socks.py:120: error: Incompatible return value type (got "list[tuple[Literal[AddressFamily.AF_INET], SocketKind, int, str, tuple[str, int]] | tuple[Literal[AddressFamily.AF_INET6], SocketKind, int, str, tuple[str, int, int, int] | tuple[int, bytes]]]", expected "list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]")  [return-value]
+ test/contrib/test_socks.py:120: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ test/contrib/test_socks.py:120: note: Consider using "Sequence" instead, which is covariant

trio (https://github.com/python-trio/trio)
+ src/trio/_socket.py:218: error: Incompatible return value type (got "list[tuple[Literal[AddressFamily.AF_INET], SocketKind, int, str, tuple[str, int]] | tuple[Literal[AddressFamily.AF_INET6], SocketKind, int, str, tuple[str, int, int, int] | tuple[int, bytes]]]", expected "list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]")  [return-value]
+ src/trio/_socket.py:218: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ src/trio/_socket.py:218: note: Consider using "Sequence" instead, which is covariant
+ src/trio/_socket.py:247: error: Argument 1 to "to_thread_run_sync" has incompatible type "Callable[[bytes | str | None, bytes | str | int | None, int, int, int, int], list[tuple[Literal[AddressFamily.AF_INET], SocketKind, int, str, tuple[str, int]] | tuple[Literal[AddressFamily.AF_INET6], SocketKind, int, str, tuple[str, int, int, int] | tuple[int, bytes]]]]"; expected "Callable[[bytes | None, bytes | str | int | None, int, int, int, int], list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]]"  [arg-type]
+ src/trio/_tests/test_socket.py:128: error: Argument 1 to "MonkeypatchedGAI" has incompatible type "Callable[[bytes | str | None, bytes | str | int | None, int, int, int, int], list[tuple[Literal[AddressFamily.AF_INET], SocketKind, int, str, tuple[str, int]] | tuple[Literal[AddressFamily.AF_INET6], SocketKind, int, str, tuple[str, int, int, int] | tuple[int, bytes]]]]"; expected "Callable[[str | bytes | None, str | bytes | int | None, int, int, int, int], list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]]"  [arg-type]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/synchronous/helpers.py:135: error: Incompatible return value type (got "list[tuple[Literal[AddressFamily.AF_INET], SocketKind, int, str, tuple[str, int]] | tuple[Literal[AddressFamily.AF_INET6], SocketKind, int, str, tuple[str, int, int, int] | tuple[int, bytes]]]", expected "list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]")  [return-value]
+ pymongo/synchronous/helpers.py:135: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ pymongo/synchronous/helpers.py:135: note: Consider using "Sequence" instead, which is covariant
+ pymongo/asynchronous/helpers.py:135: error: Incompatible return value type (got "list[tuple[Literal[AddressFamily.AF_INET], SocketKind, int, str, tuple[str, int]] | tuple[Literal[AddressFamily.AF_INET6], SocketKind, int, str, tuple[str, int, int, int] | tuple[int, bytes]]]", expected "list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]")  [return-value]
+ pymongo/asynchronous/helpers.py:135: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ pymongo/asynchronous/helpers.py:135: note: Consider using "Sequence" instead, which is covariant

@cdce8p

cdce8p commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

Mypy primer hits

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.

4 participants