mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
[red-knot] Diagnostic for possibly unbound imports (#14281)
## Summary This adds a new diagnostic when possibly unbound symbols are imported. The `TODO` comment had a question mark, do I'm not sure if this is really something that we want. This does not touch the un*declared* case, yet. relates to: #14022 ## Test Plan Updated already existing tests with new diagnostics
This commit is contained in:
parent
f82ee8ea59
commit
3bef23669f
4 changed files with 20 additions and 10 deletions
|
@ -2008,20 +2008,27 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
asname: _,
|
||||
} = alias;
|
||||
|
||||
// For possibly-unbound names, just eliminate Unbound from the type; we
|
||||
// must be in a bound path. TODO diagnostic for possibly-unbound import?
|
||||
module_ty
|
||||
.member(self.db, &ast::name::Name::new(&name.id))
|
||||
.ignore_possibly_unbound()
|
||||
.unwrap_or_else(|| {
|
||||
match module_ty.member(self.db, &ast::name::Name::new(&name.id)) {
|
||||
Symbol::Type(ty, boundness) => {
|
||||
if boundness == Boundness::PossiblyUnbound {
|
||||
self.diagnostics.add(
|
||||
AnyNodeRef::Alias(alias),
|
||||
"possibly-unbound-import",
|
||||
format_args!("Member `{name}` of module `{module_name}` is possibly unbound",),
|
||||
);
|
||||
}
|
||||
|
||||
ty
|
||||
}
|
||||
Symbol::Unbound => {
|
||||
self.diagnostics.add(
|
||||
AnyNodeRef::Alias(alias),
|
||||
"unresolved-import",
|
||||
format_args!("Module `{module_name}` has no member `{name}`",),
|
||||
);
|
||||
|
||||
Type::Unknown
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.diagnostics
|
||||
.add_unresolved_module(import_from, *level, module);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue