diff --git a/crates/ty_python_semantic/src/module_name.rs b/crates/ty_python_semantic/src/module_name.rs index 2089f82843..ff25d1fdbd 100644 --- a/crates/ty_python_semantic/src/module_name.rs +++ b/crates/ty_python_semantic/src/module_name.rs @@ -318,7 +318,7 @@ impl ModuleName { db: &dyn Db, importing_file: File, ) -> Result { - relative_module_name(db, importing_file, None, NonZeroU32::new(1).unwrap()) + Self::from_identifier_parts(db, importing_file, None, 1) } } diff --git a/crates/ty_python_semantic/src/semantic_index/builder.rs b/crates/ty_python_semantic/src/semantic_index/builder.rs index 6f7a739f78..5170abafa6 100644 --- a/crates/ty_python_semantic/src/semantic_index/builder.rs +++ b/crates/ty_python_semantic/src/semantic_index/builder.rs @@ -1555,11 +1555,11 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> { ); } } else { - self.imported_modules.extend( - module_name - .ancestors() - .zip(std::iter::repeat(ImportKind::ImportFrom)), - ); + for name in module_name.ancestors() { + self.imported_modules + .entry(name) + .or_insert(ImportKind::ImportFrom); + } } } } diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index e94d69454a..739296a197 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -13244,13 +13244,9 @@ impl<'db> ModuleLiteralType<'db> { .into_iter() .flat_map(|file| imported_modules(db, file)) .filter_map(|(submodule_name, kind)| { - Some((submodule_name.relative_to(self.module(db).name(db))?, kind)) - }) - .filter_map(|(relative_submodule, kind)| { - relative_submodule - .components() - .next() - .map(|module| (Name::from(module), *kind)) + let relative_name = submodule_name.relative_to(self.module(db).name(db))?; + let available_attribute = relative_name.components().next()?; + Some((Name::from(available_attribute), *kind)) }) }