[ty] Follow aliases when resolving stub mappings#25328
Merged
charliermarsh merged 2 commits intoMay 23, 2026
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 89.52%. The percentage of expected errors that received a diagnostic held steady at 86.99%. The number of fully passing files held steady at 90/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
not-iterable |
0 | 0 | 1 |
| Total | 0 | 0 | 1 |
Raw diff:
dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ddtrace/contrib/internal/subprocess/patch.py:321:44 error[not-iterable] Object of type `list[Unknown] | None | list[str] | ... omitted 3 union elements` may not be iterable
+ ddtrace/contrib/internal/subprocess/patch.py:321:44 error[not-iterable] Object of type `list[Unknown] | None | list[str] | Unknown | list[_T@deque | str]` may not be iterable
charliermarsh
approved these changes
May 23, 2026
anishgirianish
pushed a commit
to anishgirianish/ruff
that referenced
this pull request
May 28, 2026
## Summary
`map_stub_definition` maps a stub definition to its "real-definition"
(the same definition in a `py` file. This PR extends this mapping by
resolving aliases. For:
`main.py`:
```py
from a import bar
bar
```
`a/__init__.pyi`:
```py
def bar() -> None: ...
```
`a/__init__.py`:
```py
from .b import bar as bar
```
`a/b.py`:
```py
def bar() -> None:
"""Implementation docstring"""
```
[Playground](https://play.ty.dev/f7255368-b291-4865-b4ca-6cac35a437e8)
Clicking on `bar` in `main.py` performs the following step:
1. Resolve `bar` to `from a import bar` in `main.py`
2. Follow the import to `a/__init__.pyi` where it finds `def bar()`
3. `map_stub_definition` now tries to map `bar` to its implementation.
It finds the `from .b import bar as bar` in `a/__init__.py` and **stops
here**
The step that is missing, and this PR adds, is that stub mapping must
follow the import to the symbol's real definition.
The same applies when resolving documentation: ty first tries to get the
documentation from the stub. If that's missing, ty tries to resolve the
documentation from the implementation. However, that requires resolving
the import, because the import itself has no docstring.
Closes astral-sh/ty#2150
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
map_stub_definitionmaps a stub definition to its "real-definition" (the same definition in apyfile. This PR extends this mapping by resolving aliases. For:main.py:a/__init__.pyi:a/__init__.py:a/b.py:Playground
Clicking on
barinmain.pyperforms the following step:bartofrom a import barinmain.pya/__init__.pyiwhere it findsdef bar()map_stub_definitionnow tries to mapbarto its implementation. It finds thefrom .b import bar as barina/__init__.pyand stops hereThe step that is missing, and this PR adds, is that stub mapping must follow the import to the symbol's real definition.
The same applies when resolving documentation: ty first tries to get the documentation from the stub. If that's missing, ty tries to resolve the documentation from the implementation. However, that requires resolving the import, because the import itself has no docstring.
Closes astral-sh/ty#2150