Revert " Revert "[ty] Offer "Did you mean...?" suggestions for unresolved from imports and unresolved attributes (#18705)" (#18721)"

This reverts commit 685eac10e5.
This commit is contained in:
Alex Waygood
2025-06-17 19:36:42 +01:00
parent 1188ffccc4
commit c55a3f7977
14 changed files with 794 additions and 96 deletions

View File

@@ -205,3 +205,39 @@ python-version = "3.13"
import aifc # error: [unresolved-import]
from distutils import sysconfig # error: [unresolved-import]
```
## `from` import that has a typo
We offer a "Did you mean?" subdiagnostic suggestion if there's a name in the module that's
reasonably similar to the unresolved member.
<!-- snapshot-diagnostics -->
`foo.py`:
```py
from collections import dequee # error: [unresolved-import]
```
However, we suppress the suggestion if the only close matches in the module start with a leading
underscore:
`bar.py`:
```py
from baz import foo # error: [unresolved-import]
```
`baz.py`:
```py
_foo = 42
```
The suggestion is never suppressed if the typo itself starts with a leading underscore, however:
`eggs.py`:
```py
from baz import _fooo # error: [unresolved-import]
```