[ty] Make overload public type reachability-aware#25171
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unsupported-operator |
2 | 0 | 0 |
| Total | 2 | 0 | 0 |
Raw diff:
scikit-learn (https://github.com/scikit-learn/scikit-learn)
+ sklearn/manifold/_spectral_embedding.py:421:9 error[unsupported-operator] Operator `-=` is not supported between objects of type `csr_array[Any, tuple[int, int]]` and `dia_array[float64] | Unknown`
+ sklearn/manifold/_spectral_embedding.py:421:9 error[unsupported-operator] Operator `-=` is not supported between objects of type `csr_matrix[Any]` and `dia_array[float64] | Unknown`b0092f4 to
353324c
Compare
charliermarsh
commented
May 14, 2026
| def g(x: bytes) -> bytes: | ||
| return x | ||
|
|
||
| reveal_type(g) # revealed: (Overload[(x: int) -> int, (x: str) -> str]) | (def g(x: bytes) -> bytes) |
Member
Author
There was a problem hiding this comment.
On main, this reveals def g(x: bytes) -> bytes.
dhruvmanila
approved these changes
May 15, 2026
Member
|
Did you look at the ecosystem diff? There are two new diagnostics |
Member
Author
|
Yeah, it's correct! Before, we saw: if not SCIPY_VERSION_BELOW_1_12:
_sparse_eye_array = scipy.sparse.eye_array
else:
def _sparse_eye_array(m, n=None, *, k=0, dtype=float, format=None):
A = scipy.sparse.eye(m, n, k=k, dtype=dtype)
return scipy.sparse.dia_array(A).asformat(format)And ignored the first |
thejchap
pushed a commit
to thejchap/ruff
that referenced
this pull request
May 23, 2026
## Summary This PR makes public type construction for overloaded functions respect reachability. Before this change, we treated an overloaded functio followed by any non-overload function as an overload set followed by its implementation. That works for ordinary overloads: ```python @overload def f(x: int) -> int: ... @overload def f(x: str) -> str: ... def f(x: int | str) -> int | str: ... ``` But, it's wrong if those definitions are behind control-flow: ```python from module import f if flag(): g = f else: def g(x: bytes) -> bytes: return x ``` Here, the fallback implementation in the `else` is _not_ guaranteed to replace the imported overload set. It is just the public value of `g` on one branch -- we need to use the _union_ of the two definitions. (Previously, we would silently drop the overloaded branch and expose only the fallback function.)
anishgirianish
pushed a commit
to anishgirianish/ruff
that referenced
this pull request
May 28, 2026
## Summary This PR makes public type construction for overloaded functions respect reachability. Before this change, we treated an overloaded functio followed by any non-overload function as an overload set followed by its implementation. That works for ordinary overloads: ```python @overload def f(x: int) -> int: ... @overload def f(x: str) -> str: ... def f(x: int | str) -> int | str: ... ``` But, it's wrong if those definitions are behind control-flow: ```python from module import f if flag(): g = f else: def g(x: bytes) -> bytes: return x ``` Here, the fallback implementation in the `else` is _not_ guaranteed to replace the imported overload set. It is just the public value of `g` on one branch -- we need to use the _union_ of the two definitions. (Previously, we would silently drop the overloaded branch and expose only the fallback function.)
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
This PR makes public type construction for overloaded functions respect reachability.
Before this change, we treated an overloaded functio followed by any non-overload function as an overload set followed by its implementation. That works for ordinary overloads:
But, it's wrong if those definitions are behind control-flow:
Here, the fallback implementation in the
elseis not guaranteed to replace the imported overload set. It is just the public value ofgon one branch -- we need to use the union of the two definitions. (Previously, we would silently drop the overloaded branch and expose only the fallback function.)