Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/place.rs (Rust)

Code before:
///
/// Note that this function is only intended for use in the context of the builtins *namespace*
/// and should not be used when a symbol is being explicitly imported from the `builtins` module
/// (e.g. `from builtins import int`).
pub(crate) fn builtins_symbol<'db>(db: &'db dyn Db, symbol: &str) -> PlaceAndQualifiers<'db> {
    let resolver = |module: Module<'_>| {
        let file = module.file(db)?;
        let found_symbol = symbol_impl(
            db,
            global_scope(db, file),
            symbol,
            RequiresExplicitReExport::Yes,
            ConsideredDefinitions::EndOfScope,
        )
        .or_fall_back_to(db, || {
            // We're looking up in the builtins namespace and not the module, so we should
            // do the normal lookup in `types.ModuleType` and not the special one as in
            // `imported_symbol`.
            module_type_implicit_global_symbol(db, symbol)
        });
        // If this symbol is not present in project-level builtins, search in the default ones.
        found_symbol
            .ignore_possibly_undefined()
            .map(|_| found_symbol)
    };
    resolve_module_confident(db, &ModuleName::new("__builtins__").unwrap())
        .and_then(&resolver)
        .or_else(|| resolve_module_confident(db, &KnownModule::Builtins.name()).and_then(resolver))
        .unwrap_or_default()
}

/// Lookup the type of `symbol` in a given known module.
///
/// Returns `Place::Undefined` if the given known module cannot be resolved for some reason.
pub(crate) fn known_module_symbol<'db>(
    db: &'db dyn Db,
    known_module: KnownModule,
    symbol: &str,
) -> PlaceAndQualifiers<'db> {
    resolve_module_confident(db, &known_module.name())
        .and_then(|module| {
            let file = module.file(db)?;
            Some(imported_symbol(db, file, symbol, None))
        })
        .unwrap_or_default()
}

/// Lookup the type of `symbol` in the `typing` module namespace.
///
/// Returns `Place::Undefined` if the `typing` module isn't available for some reason.
#[inline]

Review comment (suggestion):
```suggestion
    resolve_module_confident(db, &ModuleName::new_static("__builtins__").unwrap())
```

Code after:
///
/// Returns `Place::Undefined` if the `builtins` module isn't available for some reason.
///
/// Note that this function is only intended for use in the context of the builtins *namespace*
/// and should not be used when a symbol is being explicitly imported from the `builtins` module
/// (e.g. `from builtins import int`).
pub(crate) fn builtins_symbol<'db>(db: &'db dyn Db, symbol: &str) -> PlaceAndQualifiers<'db> {
    let resolver = |module: Module<'_>| {
        let file = module.file(db)?;
        let found_symbol = symbol_impl(
            db,
            global_scope(db, file),
            symbol,
            RequiresExplicitReExport::Yes,
            ConsideredDefinitions::EndOfScope,
        )
        .or_fall_back_to(db, || {
            // We're looking up in the builtins namespace and not the module, so we should
            // do the normal lookup in `types.ModuleType` and not the special one as in
            // `imported_symbol`.
            module_type_implicit_global_symbol(db, symbol)
        });
        // If this symbol is not present in project-level builtins, search in the default ones.
        found_symbol
            .ignore_possibly_undefined()
            .map(|_| found_symbol)
    };
    resolve_module_confident(db, &ModuleName::new_static("__builtins__").unwrap())
        .and_then(&resolver)
        .or_else(|| resolve_module_confident(db, &KnownModule::Builtins.name()).and_then(resolver))
        .unwrap_or_default()
}

/// Lookup the type of `symbol` in a given known module.
///
/// Returns `Place::Undefined` if the given known module cannot be resolved for some reason.
pub(crate) fn known_module_symbol<'db>(
    db: &'db dyn Db,
    known_module: KnownModule,
    symbol: &str,
) -> PlaceAndQualifiers<'db> {
    resolve_module_confident(db, &known_module.name())
        .and_then(|module| {
            let file = module.file(db)?;
            Some(imported_symbol(db, file, symbol, None))
        })
        .unwrap_or_default()
}

/// Lookup the type of `symbol` in the `typing` module namespace.
///