[ty] Fix relative imports in stub packages (#18132)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

This commit is contained in:
Micha Reiser 2025-05-16 15:30:10 +02:00 committed by GitHub
parent e677cabd69
commit 1ba56b4bc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -4,7 +4,6 @@ use std::fmt;
use std::sync::Arc;
use camino::{Utf8Path, Utf8PathBuf};
use ruff_db::files::{File, FileError, system_path_to_file, vendored_path_to_file};
use ruff_db::system::{System, SystemPath, SystemPathBuf};
use ruff_db::vendored::{VendoredPath, VendoredPathBuf};
@ -189,7 +188,18 @@ impl ModulePath {
stdlib_path_to_module_name(relative_path)
} else {
let parent = relative_path.parent()?;
let parent_components = parent.components().map(|component| component.as_str());
let parent_components = parent.components().enumerate().map(|(index, component)| {
let component = component.as_str();
// For stub packages, strip the `-stubs` suffix from the first component
// because it isn't a valid module name part AND the module name is the name without the `-stubs`.
if index == 0 {
component.strip_suffix("-stubs").unwrap_or(component)
} else {
component
}
});
let skip_final_part =
relative_path.ends_with("__init__.py") || relative_path.ends_with("__init__.pyi");
if skip_final_part {