MCPcopy Index your code
hub / github.com/RustPython/RustPython / is_name_imported

Method is_name_imported

crates/codegen/src/compile.rs:741–763  ·  view source on GitHub ↗

Check if a name is imported in current scope or any enclosing scope.

(&self, name: &str)

Source from the content-addressed store, hash-verified

739
740 /// Check if a name is imported in current scope or any enclosing scope.
741 fn is_name_imported(&self, name: &str) -> bool {
742 let current = self.current_symbol_table();
743 if let Some(sym) = current.symbols.get(name) {
744 if sym.flags.contains(SymbolFlags::IMPORTED) {
745 // Module/class scope imports use plain LOAD_ATTR
746 // Function-local imports use method mode (scope is Local)
747 return !matches!(
748 current.typ,
749 CompilerScope::Function | CompilerScope::AsyncFunction | CompilerScope::Lambda
750 );
751 }
752 if sym.scope == SymbolScope::Local {
753 return false;
754 }
755 }
756 // Check enclosing scopes for module-level imports accessed as globals
757 self.symbol_table_stack.iter().rev().skip(1).any(|table| {
758 table
759 .symbols
760 .get(name)
761 .is_some_and(|sym| sym.flags.contains(SymbolFlags::IMPORTED))
762 })
763 }
764
765 /// Get the cell-relative index of a free variable.
766 /// Returns ncells + freevar_idx. Fixed up to localsplus index during finalize.

Callers

nothing calls this directly

Calls 6

current_symbol_tableMethod · 0.80
getMethod · 0.45
containsMethod · 0.45
skipMethod · 0.45
revMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected