[red-knot] Rename some methods in the module resolver (#12517)

This commit is contained in:
Alex Waygood 2024-07-25 20:28:48 +01:00 committed by GitHub
parent 5ce80827d2
commit 2ceac5f868
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 12 deletions

View file

@ -40,7 +40,7 @@ impl<'db> Iterator for SystemModuleSearchPathsIter<'db> {
loop { loop {
let next = self.inner.next()?; let next = self.inner.next()?;
if let Some(system_path) = next.as_system_path_buf() { if let Some(system_path) = next.as_system_path() {
return Some(system_path); return Some(system_path);
} }
} }

View file

@ -224,7 +224,7 @@ impl PartialEq<SystemPathBuf> for ModulePath {
relative_path, relative_path,
} = self; } = self;
search_path search_path
.as_system_path_buf() .as_system_path()
.and_then(|search_path| other.strip_prefix(search_path).ok()) .and_then(|search_path| other.strip_prefix(search_path).ok())
.is_some_and(|other_relative_path| other_relative_path.as_utf8_path() == relative_path) .is_some_and(|other_relative_path| other_relative_path.as_utf8_path() == relative_path)
} }
@ -243,7 +243,7 @@ impl PartialEq<VendoredPathBuf> for ModulePath {
relative_path, relative_path,
} = self; } = self;
search_path search_path
.as_vendored_path_buf() .as_vendored_path()
.and_then(|search_path| other.strip_prefix(search_path).ok()) .and_then(|search_path| other.strip_prefix(search_path).ok())
.is_some_and(|other_relative_path| other_relative_path.as_utf8_path() == relative_path) .is_some_and(|other_relative_path| other_relative_path.as_utf8_path() == relative_path)
} }
@ -511,7 +511,7 @@ impl SearchPath {
} }
#[must_use] #[must_use]
pub(crate) fn as_system_path_buf(&self) -> Option<&SystemPath> { pub(crate) fn as_system_path(&self) -> Option<&SystemPath> {
match &*self.0 { match &*self.0 {
SearchPathInner::Extra(path) SearchPathInner::Extra(path)
| SearchPathInner::FirstParty(path) | SearchPathInner::FirstParty(path)
@ -523,7 +523,7 @@ impl SearchPath {
} }
#[must_use] #[must_use]
pub(crate) fn as_vendored_path_buf(&self) -> Option<&VendoredPath> { pub(crate) fn as_vendored_path(&self) -> Option<&VendoredPath> {
match &*self.0 { match &*self.0 {
SearchPathInner::StandardLibraryVendored(path) => Some(path), SearchPathInner::StandardLibraryVendored(path) => Some(path),
SearchPathInner::Extra(_) SearchPathInner::Extra(_)
@ -537,7 +537,7 @@ impl SearchPath {
impl PartialEq<SystemPath> for SearchPath { impl PartialEq<SystemPath> for SearchPath {
fn eq(&self, other: &SystemPath) -> bool { fn eq(&self, other: &SystemPath) -> bool {
self.as_system_path_buf().is_some_and(|path| path == other) self.as_system_path().is_some_and(|path| path == other)
} }
} }
@ -561,8 +561,7 @@ impl PartialEq<SearchPath> for SystemPathBuf {
impl PartialEq<VendoredPath> for SearchPath { impl PartialEq<VendoredPath> for SearchPath {
fn eq(&self, other: &VendoredPath) -> bool { fn eq(&self, other: &VendoredPath) -> bool {
self.as_vendored_path_buf() self.as_vendored_path().is_some_and(|path| path == other)
.is_some_and(|path| path == other)
} }
} }

View file

@ -158,7 +158,7 @@ fn try_resolve_module_resolution_settings(
FxHashSet::with_capacity_and_hasher(static_search_paths.len(), FxBuildHasher); FxHashSet::with_capacity_and_hasher(static_search_paths.len(), FxBuildHasher);
static_search_paths.retain(|path| { static_search_paths.retain(|path| {
if let Some(path) = path.as_system_path_buf() { if let Some(path) = path.as_system_path() {
seen_paths.insert(path.to_path_buf()) seen_paths.insert(path.to_path_buf())
} else { } else {
true true
@ -204,7 +204,7 @@ pub(crate) fn editable_install_resolution_paths(db: &dyn Db) -> Vec<SearchPath>
if let Some(site_packages) = site_packages { if let Some(site_packages) = site_packages {
let site_packages = site_packages let site_packages = site_packages
.as_system_path_buf() .as_system_path()
.expect("Expected site-packages never to be a VendoredPath!"); .expect("Expected site-packages never to be a VendoredPath!");
// As well as modules installed directly into `site-packages`, // As well as modules installed directly into `site-packages`,
@ -225,7 +225,7 @@ pub(crate) fn editable_install_resolution_paths(db: &dyn Db) -> Vec<SearchPath>
let mut existing_paths: FxHashSet<_> = static_search_paths let mut existing_paths: FxHashSet<_> = static_search_paths
.iter() .iter()
.filter_map(|path| path.as_system_path_buf()) .filter_map(|path| path.as_system_path())
.map(Cow::Borrowed) .map(Cow::Borrowed)
.collect(); .collect();
@ -234,7 +234,7 @@ pub(crate) fn editable_install_resolution_paths(db: &dyn Db) -> Vec<SearchPath>
for pth_file in &all_pth_files { for pth_file in &all_pth_files {
for installation in pth_file.editable_installations() { for installation in pth_file.editable_installations() {
if existing_paths.insert(Cow::Owned( if existing_paths.insert(Cow::Owned(
installation.as_system_path_buf().unwrap().to_path_buf(), installation.as_system_path().unwrap().to_path_buf(),
)) { )) {
dynamic_paths.push(installation); dynamic_paths.push(installation);
} }