Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Fix bug where module resolution would not be invalidated if an entire package was deleted #12378

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions crates/red_knot_module_resolver/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,9 @@ impl<'a> ModuleResolutionPathRefInner<'a> {

#[must_use]
fn is_regular_package(&self, search_path: Self, resolver: &ResolverState) -> bool {
fn is_non_stdlib_pkg(state: &ResolverState, path: &SystemPath) -> bool {
let file_system = state.system();
file_system.path_exists(&path.join("__init__.py"))
|| file_system.path_exists(&path.join("__init__.pyi"))
fn is_non_stdlib_pkg(resolver: &ResolverState, path: &SystemPath) -> bool {
system_path_to_file(resolver.db.upcast(), path.join("__init__.py")).is_some()
|| system_path_to_file(resolver.db.upcast(), path.join("__init__.py")).is_some()
}

match (self, search_path) {
Expand All @@ -387,8 +386,13 @@ impl<'a> ModuleResolutionPathRefInner<'a> {
match Self::query_stdlib_version( path, search_path, &stdlib_root, resolver) {
TypeshedVersionsQueryResult::DoesNotExist => false,
TypeshedVersionsQueryResult::Exists | TypeshedVersionsQueryResult::MaybeExists => match path {
FilePathRef::System(path) => resolver.db.system().path_exists(&path.join("__init__.pyi")),
FilePathRef::Vendored(path) => resolver.db.vendored().exists(path.join("__init__.pyi")),
FilePathRef::System(path) => system_path_to_file(resolver.db.upcast(),path.join("__init__.pyi")).is_some(),
// No need to use `vendored_path_to_file` here:
// (1) The vendored filesystem is immutable, so we don't need to worry about Salsa invalidation
// (2) The caching Salsa provides probably won't speed us up that much
// (TODO: check that assumption when we're able to run red-knot on larger code bases)
// (3) We don't need the `File` object that `vendored_path_to_file` would return; we just need to know if the file exists
FilePathRef::Vendored(path) => resolver.db.vendored().exists(path.join("__init__.pyi"))
},
}
}
Expand Down
Loading