[ty] Detect disjointness due to incompatible generic specializations#24822
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unresolved-attribute |
0 | 3 | 0 |
invalid-argument-type |
0 | 0 | 2 |
type-assertion-failure |
0 | 0 | 1 |
| Total | 0 | 3 | 3 |
Raw diff:
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
- tests/test_api_types.py:372:9 error[type-assertion-failure] Type `Categorical[str]` does not match asserted type `Categorical[int]`
+ tests/test_api_types.py:372:9 error[type-assertion-failure] Type `Categorical[Unknown]` does not match asserted type `Categorical[int]`
pip (https://github.com/pypa/pip)
- src/pip/_vendor/urllib3/response.py:475:43 error[invalid-argument-type] Argument to `HTTPHeaderDict.__init__` is incorrect: Expected `Mapping[str, str] | Iterable[tuple[str, str]] | HasGettableStringKeys | None`, found `(Mapping[str, str] & ~HTTPHeaderDict) | (Mapping[bytes, bytes] & ~HTTPHeaderDict) | None`
+ src/pip/_vendor/urllib3/response.py:475:43 error[invalid-argument-type] Argument to `HTTPHeaderDict.__init__` is incorrect: Expected `Mapping[str, str] | Iterable[tuple[str, str]] | HasGettableStringKeys | None`, found `(Mapping[str, str] & ~HTTPHeaderDict) | Mapping[bytes, bytes] | None`
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/server/orchestration/global_policy.py:462:13 error[unresolved-attribute] Attribute `state_details` is not defined on `None` in union `State | None`
- src/prefect/server/orchestration/global_policy.py:466:13 error[unresolved-attribute] Attribute `state_details` is not defined on `None` in union `State | None`
- src/prefect/server/orchestration/global_policy.py:467:13 error[unresolved-attribute] Attribute `state_details` is not defined on `None` in union `State | None`
urllib3 (https://github.com/urllib3/urllib3)
- src/urllib3/response.py:484:43 error[invalid-argument-type] Argument to `HTTPHeaderDict.__init__` is incorrect: Expected `Mapping[str, str] | Iterable[tuple[str, str]] | HasGettableStringKeys | None`, found `(Mapping[str, str] & ~HTTPHeaderDict) | (Mapping[bytes, bytes] & ~HTTPHeaderDict) | None`
+ src/urllib3/response.py:484:43 error[invalid-argument-type] Argument to `HTTPHeaderDict.__init__` is incorrect: Expected `Mapping[str, str] | Iterable[tuple[str, str]] | HasGettableStringKeys | None`, found `(Mapping[str, str] & ~HTTPHeaderDict) | Mapping[bytes, bytes] | None`
Merging this PR will not alter performance
Comparing Footnotes
|
e59076e to
07ec5a7
Compare
4096f1c to
ff5eb8e
Compare
d2714f9 to
d4595d9
Compare
fd77244 to
19e87fd
Compare
73769bc to
9a2ce88
Compare
38f6527 to
946ed20
Compare
946ed20 to
03ad757
Compare
carljm
approved these changes
Jun 3, 2026
carljm
left a comment
Contributor
There was a problem hiding this comment.
I tried something a bit different here -- rather than making review comments, I iterated with Codex on the needed changes directly, and then put them up as a stacked PR, with comments explaining what I did and why: #25583
Take a look at the stacked PR and comments, and merge it into this PR if it looks good to you. Once that's done, this PR is good to merge as far as I'm concerned.
carljm
added a commit
that referenced
this pull request
Jun 3, 2026
* origin/main: (114 commits) [ty] Detect disjointness due to incompatible generic specializations (#24822) Update Rust crate memchr to v2.8.1 (#25586) [ty] Reject Self in type aliases (#25529) Update Rust crate log to v0.4.30 (#25572) Update Rust crate mimalloc to v0.1.52 (#25573) Update Rust crate similar to v3.1.1 (#25575) Update docker/setup-buildx-action action to v4.1.0 (#25580) Update docker/metadata-action action to v6.1.0 (#25579) Update docker/login-action action to v4.2.0 (#25578) Update docker/build-push-action action to v7.2.0 (#25577) Update taiki-e/install-action action to v2.79.9 (#25576) Update Rust crate serde_json to v1.0.150 (#25574) Update Rust crate assert_fs to v1.1.4 (#25570) Update prek dependencies (#25569) Update dependency ruff to v0.15.15 (#25568) Update dependency pyright to v1.1.410 (#25566) Update dependency astral-sh/uv to v0.11.18 (#25565) [ty] don't needlessly disambiguate same type alias (#25563) [ty] fix variance inference for nested type aliases (#25567) [ty] treat union-bound typevars like unions for possibly-missing-attribute (#25561) ... # Conflicts: # crates/ty_python_semantic/src/types/class.rs # crates/ty_python_semantic/src/types/generics.rs # crates/ty_python_semantic/src/types/type_alias.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Prior to this change, we did not recognize that generic specializations with
incompatible invariant type arguments are disjoint. A single value cannot simultaneously inhabit two specializations of an invariant generic class when their fully static arguments are not equivalent:
We now recognize disjointness between classes whose inherited bases contain incompatible specializations of the same invariant generic class.
(Covariant generic specializations are not treated as disjoint by this change; for example, an empty container can inhabit both
Sequence[int]andSequence[str]).Closes astral-sh/ty#3314.