Skip to content

Commit 685eac1

Browse files
authored
Revert "[ty] Offer "Did you mean...?" suggestions for unresolved from imports and unresolved attributes (#18705)" (#18721)
1 parent a93992f commit 685eac1

14 files changed

+96
-794
lines changed

_typos.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ extend-exclude = [
88
# words naturally. It's annoying to have to make all
99
# of them actually words. So just ignore typos here.
1010
"crates/ty_ide/src/completion.rs",
11-
# Same for "Did you mean...?" levenshtein tests.
12-
"crates/ty_python_semantic/src/types/diagnostic/levenshtein.rs",
1311
]
1412

1513
[default.extend-words]

crates/ty/docs/rules.md

Lines changed: 56 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty_python_semantic/resources/mdtest/attributes.md

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,57 +2167,6 @@ reveal_type(Foo.BAR.value) # revealed: @Todo(Attribute access on enum classes)
21672167
reveal_type(Foo.__members__) # revealed: @Todo(Attribute access on enum classes)
21682168
```
21692169

2170-
## Suggestions for obvious typos
2171-
2172-
<!-- snapshot-diagnostics -->
2173-
2174-
For obvious typos, we add a "Did you mean...?" suggestion to the diagnostic.
2175-
2176-
```py
2177-
import collections
2178-
2179-
print(collections.dequee) # error: [unresolved-attribute]
2180-
```
2181-
2182-
But the suggestion is suppressed if the only close matches start with a leading underscore:
2183-
2184-
```py
2185-
class Foo:
2186-
_bar = 42
2187-
2188-
print(Foo.bar) # error: [unresolved-attribute]
2189-
```
2190-
2191-
The suggestion is not suppressed if the typo itself starts with a leading underscore, however:
2192-
2193-
```py
2194-
print(Foo._barr) # error: [unresolved-attribute]
2195-
```
2196-
2197-
And in method contexts, the suggestion is never suppressed if accessing an attribute on an instance
2198-
of the method's enclosing class:
2199-
2200-
```py
2201-
class Bar:
2202-
_attribute = 42
2203-
2204-
def f(self, x: "Bar"):
2205-
# TODO: we should emit `[unresolved-attribute]` here, should have the same behaviour as `x.attribute` below
2206-
print(self.attribute)
2207-
2208-
# We give a suggestion here, even though the only good candidates start with underscores and the typo does not,
2209-
# because we're in a method context and `x` is an instance of the enclosing class.
2210-
print(x.attribute) # error: [unresolved-attribute]
2211-
2212-
class Baz:
2213-
def f(self, x: Bar):
2214-
# No suggestion is given here, because:
2215-
# - the good suggestions all start with underscores
2216-
# - the typo does not start with an underscore
2217-
# - We *are* in a method context, but `x` is not an instance of the enclosing class
2218-
print(x.attribute) # error: [unresolved-attribute]
2219-
```
2220-
22212170
## References
22222171

22232172
Some of the tests in the *Class and instance variables* section draw inspiration from

crates/ty_python_semantic/resources/mdtest/import/basic.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -205,39 +205,3 @@ python-version = "3.13"
205205
import aifc # error: [unresolved-import]
206206
from distutils import sysconfig # error: [unresolved-import]
207207
```
208-
209-
## `from` import that has a typo
210-
211-
We offer a "Did you mean?" subdiagnostic suggestion if there's a name in the module that's
212-
reasonably similar to the unresolved member.
213-
214-
<!-- snapshot-diagnostics -->
215-
216-
`foo.py`:
217-
218-
```py
219-
from collections import dequee # error: [unresolved-import]
220-
```
221-
222-
However, we suppress the suggestion if the only close matches in the module start with a leading
223-
underscore:
224-
225-
`bar.py`:
226-
227-
```py
228-
from baz import foo # error: [unresolved-import]
229-
```
230-
231-
`baz.py`:
232-
233-
```py
234-
_foo = 42
235-
```
236-
237-
The suggestion is never suppressed if the typo itself starts with a leading underscore, however:
238-
239-
`eggs.py`:
240-
241-
```py
242-
from baz import _fooo # error: [unresolved-import]
243-
```

crates/ty_python_semantic/resources/mdtest/snapshots/attributes.md_-_Attributes_-_Suggestions_for_obvi…_(bf7b28ef99f0ec16).snap

Lines changed: 0 additions & 115 deletions
This file was deleted.

crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_`from`_import_that_h…_(3caffc60d8390adf).snap

Lines changed: 0 additions & 69 deletions
This file was deleted.

crates/ty_python_semantic/src/semantic_model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::module_resolver::{Module, resolve_module};
1010
use crate::semantic_index::ast_ids::HasScopedExpressionId;
1111
use crate::semantic_index::place::FileScopeId;
1212
use crate::semantic_index::semantic_index;
13-
use crate::types::all_members::all_declarations_and_bindings;
13+
use crate::types::ide_support::all_declarations_and_bindings;
1414
use crate::types::{Type, binding_type, infer_scope_types};
1515

1616
pub struct SemanticModel<'db> {

crates/ty_python_semantic/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use crate::semantic_index::definition::Definition;
3838
use crate::semantic_index::place::{ScopeId, ScopedPlaceId};
3939
use crate::semantic_index::{imported_modules, place_table, semantic_index};
4040
use crate::suppression::check_suppressions;
41-
pub use crate::types::all_members::all_members;
4241
use crate::types::call::{Binding, Bindings, CallArgumentTypes, CallableBinding};
4342
pub(crate) use crate::types::class_base::ClassBase;
4443
use crate::types::context::{LintDiagnosticGuard, LintDiagnosticGuardBuilder};
@@ -47,6 +46,7 @@ use crate::types::function::{
4746
DataclassTransformerParams, FunctionSpans, FunctionType, KnownFunction,
4847
};
4948
use crate::types::generics::{GenericContext, PartialSpecialization, Specialization};
49+
pub use crate::types::ide_support::all_members;
5050
use crate::types::infer::infer_unpack_types;
5151
use crate::types::mro::{Mro, MroError, MroIterator};
5252
pub(crate) use crate::types::narrow::infer_narrowing_constraint;
@@ -58,7 +58,6 @@ use instance::Protocol;
5858
pub use instance::{NominalInstanceType, ProtocolInstanceType};
5959
pub use special_form::SpecialFormType;
6060

61-
pub(crate) mod all_members;
6261
mod builder;
6362
mod call;
6463
mod class;
@@ -68,6 +67,7 @@ mod diagnostic;
6867
mod display;
6968
mod function;
7069
mod generics;
70+
pub(crate) mod ide_support;
7171
mod infer;
7272
mod instance;
7373
mod mro;

crates/ty_python_semantic/src/types/call/bind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::types::signatures::{Parameter, ParameterForm};
2727
use crate::types::{
2828
BoundMethodType, ClassLiteral, DataclassParams, KnownClass, KnownInstanceType,
2929
MethodWrapperKind, PropertyInstanceType, SpecialFormType, TupleType, TypeMapping, UnionType,
30-
WrapperDescriptorKind, all_members, todo_type,
30+
WrapperDescriptorKind, ide_support, todo_type,
3131
};
3232
use ruff_db::diagnostic::{Annotation, Diagnostic, Severity, SubDiagnostic};
3333
use ruff_python_ast as ast;
@@ -669,7 +669,7 @@ impl<'db> Bindings<'db> {
669669
if let [Some(ty)] = overload.parameter_types() {
670670
overload.set_return_type(TupleType::from_elements(
671671
db,
672-
all_members::all_members(db, *ty)
672+
ide_support::all_members(db, *ty)
673673
.into_iter()
674674
.sorted()
675675
.map(|member| Type::string_literal(db, &member)),

crates/ty_python_semantic/src/types/class.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ pub enum ClassType<'db> {
225225

226226
#[salsa::tracked]
227227
impl<'db> ClassType<'db> {
228-
pub(super) fn is_protocol(self, db: &'db dyn Db) -> bool {
229-
self.class_literal(db).0.is_protocol(db)
230-
}
231-
232228
pub(super) fn normalized(self, db: &'db dyn Db) -> Self {
233229
match self {
234230
Self::NonGeneric(_) => self,

0 commit comments

Comments
 (0)