This commit is contained in:
Aria Desires 2025-09-18 21:08:49 -04:00
parent 793d0d0dd4
commit 7ef86c9637
2 changed files with 2 additions and 38 deletions

View File

@ -461,25 +461,8 @@ impl File {
/// Returns `true` if the file is an `__init__.py(i)`
pub fn is_init(self, db: &dyn Db) -> bool {
let (name, extension) = match self.path(db) {
FilePath::System(path) => (
path.file_stem(),
path.extension().and_then(PySourceType::try_from_extension),
),
FilePath::Vendored(path) => (
path.file_stem(),
path.extension().and_then(PySourceType::try_from_extension),
),
FilePath::SystemVirtual(path) => (
path.file_stem(),
path.extension().and_then(PySourceType::try_from_extension),
),
};
name == Some("__init__")
&& matches!(
extension,
Some(PySourceType::Python) | Some(PySourceType::Stub)
)
let path = self.path(db).as_str();
path.ends_with("__init__.py") || path.ends_with("__init__.pyi")
}
pub fn source_type(self, db: &dyn Db) -> PySourceType {

View File

@ -754,25 +754,6 @@ impl SystemVirtualPath {
Path::new(&self.0).extension().and_then(|ext| ext.to_str())
}
/// Extracts the file stem, if possible
///
/// ```
/// use ruff_db::system::SystemVirtualPath;
///
/// assert_eq!("Untitled-1", SystemVirtualPath::new("untitled:Untitled-1").extension().unwrap());
/// assert_eq!("Untitled-1", SystemVirtualPath::new("untitled:Untitled-1.ipynb").extension().unwrap());
/// assert_eq!("Untitled-1", SystemVirtualPath::new("vscode-notebook-cell:Untitled-1.ipynb").extension().unwrap());
/// assert_eq!("__init__", SystemVirtualPath::new("untitled:init.py").extension().unwrap());
/// assert_eq!("__init__", SystemVirtualPath::new("untitled:foo/init.pyi").extension().unwrap());
/// ```
///
/// See [`Path::file_stem`] for more details.
pub fn file_stem(&self) -> Option<&str> {
Path::new(&self.0)
.file_stem()
.and_then(|stem| stem.to_str())
}
/// Returns the path as a string slice.
#[inline]
pub fn as_str(&self) -> &str {