mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 11:05:45 +00:00
Calculate import level at parsing
This commit is contained in:
parent
a6808efab7
commit
96e49f195d
2 changed files with 24 additions and 2 deletions
|
@ -252,13 +252,16 @@ impl Compiler {
|
|||
module,
|
||||
symbols,
|
||||
alias,
|
||||
level,
|
||||
} in import_parts
|
||||
{
|
||||
let level = *level;
|
||||
if let Some(alias) = alias {
|
||||
// import module as alias
|
||||
self.emit(Instruction::Import {
|
||||
name: module.clone(),
|
||||
symbols: vec![],
|
||||
level,
|
||||
});
|
||||
self.store_name(&alias);
|
||||
} else if symbols.is_empty() {
|
||||
|
@ -266,6 +269,7 @@ impl Compiler {
|
|||
self.emit(Instruction::Import {
|
||||
name: module.clone(),
|
||||
symbols: vec![],
|
||||
level,
|
||||
});
|
||||
self.store_name(&module.clone());
|
||||
} else {
|
||||
|
@ -276,6 +280,7 @@ impl Compiler {
|
|||
// from module import *
|
||||
self.emit(Instruction::ImportStar {
|
||||
name: module.clone(),
|
||||
level,
|
||||
});
|
||||
} else {
|
||||
// from module import symbol
|
||||
|
@ -292,6 +297,7 @@ impl Compiler {
|
|||
self.emit(Instruction::Import {
|
||||
name: module.clone(),
|
||||
symbols: symbols_strings,
|
||||
level,
|
||||
});
|
||||
names.iter().rev().for_each(|name| self.store_name(&name));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue