From 5b00ec981bde8f253867c29ed885d04921042328 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:02:45 -0400 Subject: [PATCH] [ty] Split out another constructor for `ModuleName` This makes it a little more flexible to call. For example, we might have a `StmtImport` and not a `StmtImportFrom`. --- crates/ty_python_semantic/src/module_name.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/src/module_name.rs b/crates/ty_python_semantic/src/module_name.rs index 79a9c0fd63..df7ae09e2a 100644 --- a/crates/ty_python_semantic/src/module_name.rs +++ b/crates/ty_python_semantic/src/module_name.rs @@ -285,10 +285,16 @@ impl ModuleName { range: _, node_index: _, } = node; + Self::from_identifier_parts(db, importing_file, module.as_deref(), *level) + } - let module = module.as_deref(); - - if let Some(level) = NonZeroU32::new(*level) { + pub(crate) fn from_identifier_parts( + db: &dyn Db, + importing_file: File, + module: Option<&str>, + level: u32, + ) -> Result { + if let Some(level) = NonZeroU32::new(level) { relative_module_name(db, importing_file, module, level) } else { module