[red-knot] Resolve symbols from builtins.pyi in the stdlib if they cannot be found in other scopes (#12390)

Co-authored-by: Carl Meyer <carl@astral.sh>
This commit is contained in:
Alex Waygood 2024-07-19 17:44:56 +01:00 committed by GitHub
parent 1c7b84059e
commit d8cf8ac2ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 231 additions and 11 deletions

View file

@ -0,0 +1,16 @@
use red_knot_module_resolver::{resolve_module, ModuleName};
use crate::semantic_index::global_scope;
use crate::semantic_index::symbol::ScopeId;
use crate::Db;
/// Salsa query to get the builtins scope.
///
/// Can return None if a custom typeshed is used that is missing `builtins.pyi`.
#[salsa::tracked]
pub(crate) fn builtins_scope(db: &dyn Db) -> Option<ScopeId<'_>> {
let builtins_name =
ModuleName::new_static("builtins").expect("Expected 'builtins' to be a valid module name");
let builtins_file = resolve_module(db.upcast(), builtins_name)?.file();
Some(global_scope(db, builtins_file))
}