Check if a name is imported in current scope or any enclosing scope.
(&self, name: &str)
| 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. |