From 9b14428d826aba105c8c9b0959ee1e532a008c7a Mon Sep 17 00:00:00 2001 From: fda-odoo Date: Thu, 6 Nov 2025 17:43:48 +0100 Subject: [PATCH] [FIX] PYI importing PYD detected as self import --- server/src/core/python_arch_builder.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server/src/core/python_arch_builder.rs b/server/src/core/python_arch_builder.rs index 98f1ab80..fc6f9843 100644 --- a/server/src/core/python_arch_builder.rs +++ b/server/src/core/python_arch_builder.rs @@ -210,19 +210,24 @@ impl PythonArchBuilder { } } let mut dep_to_add = vec![]; - let symbol = import_result.symbol.borrow(); - if symbol.typ() != SymType::COMPILED { - for (name, loc_syms) in symbol.iter_symbols() { - if all_name_allowed || name_filter.contains(&name) { - let variable = self.sym_stack.last().unwrap().borrow_mut().add_new_variable(session, OYarn::from(name.clone()), &import_result.range); - let mut loc = variable.borrow_mut(); - loc.as_variable_mut().is_import_variable = true; - loc.as_variable_mut().evaluations = Evaluation::from_sections(&symbol, loc_syms); - dep_to_add.push(variable.clone()); + let sym_type = import_result.symbol.borrow().typ(); + if sym_type != SymType::COMPILED { + if !Rc::ptr_eq(self.sym_stack.last().unwrap(), &import_result.symbol) { /*We have to check that the imported symbol is not the current one. It can + happen for example in a .pyi that is importing the .pyd file with the same name. As both exists, odools will try to import the pyi a second time in the same file, + and so create a borrow error here + */ + let symbol = import_result.symbol.borrow(); + for (name, loc_syms) in symbol.iter_symbols() { + if all_name_allowed || name_filter.contains(&name) { + let variable = self.sym_stack.last().unwrap().borrow_mut().add_new_variable(session, OYarn::from(name.clone()), &import_result.range); + let mut loc = variable.borrow_mut(); + loc.as_variable_mut().is_import_variable = true; + loc.as_variable_mut().evaluations = Evaluation::from_sections(&symbol, loc_syms); + dep_to_add.push(variable.clone()); + } } } } - drop(symbol); for sym in dep_to_add { let mut sym_bw = sym.borrow_mut(); let evaluation = &sym_bw.as_variable_mut().evaluations[0];