[red-knot] Trust all symbols in stub files (#17588)

## Summary

*Generally* trust undeclared symbols in stubs, not just at the module
level.

Follow-up on the discussion
[here](https://github.com/astral-sh/ruff/pull/17577#discussion_r2055945909).

## Test Plan

New Markdown test.
This commit is contained in:
David Peter
2025-04-23 20:07:29 +02:00
committed by GitHub
parent e91e2f49db
commit e170fe493d
3 changed files with 64 additions and 9 deletions

View File

@@ -115,10 +115,6 @@ impl<'db> ScopeId<'db> {
self.node(db).scope_kind().is_function_like()
}
pub(crate) fn is_module_scope(self, db: &'db dyn Db) -> bool {
self.node(db).scope_kind().is_module()
}
pub(crate) fn is_type_parameter(self, db: &'db dyn Db) -> bool {
self.node(db).scope_kind().is_type_parameter()
}
@@ -267,10 +263,6 @@ impl ScopeKind {
matches!(self, ScopeKind::Class)
}
pub(crate) fn is_module(self) -> bool {
matches!(self, ScopeKind::Module)
}
pub(crate) fn is_type_parameter(self) -> bool {
matches!(self, ScopeKind::Annotation | ScopeKind::TypeAlias)
}

View File

@@ -593,7 +593,7 @@ fn symbol_by_id<'db>(
"__slots__" | "TYPE_CHECKING"
);
if scope.is_module_scope(db) && scope.file(db).is_stub(db.upcast()) {
if scope.file(db).is_stub(db.upcast()) {
// We generally trust module-level undeclared symbols in stubs and do not union
// with `Unknown`. If we don't do this, simple aliases like `IOError = OSError` in
// stubs would result in `IOError` being a union of `OSError` and `Unknown`, which