diff --git a/crates/ruff_db/src/files.rs b/crates/ruff_db/src/files.rs index 4d2f1b48d4..14a92c55ba 100644 --- a/crates/ruff_db/src/files.rs +++ b/crates/ruff_db/src/files.rs @@ -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 { diff --git a/crates/ruff_db/src/system/path.rs b/crates/ruff_db/src/system/path.rs index 2a91bf6b9e..d0ff92e5d8 100644 --- a/crates/ruff_db/src/system/path.rs +++ b/crates/ruff_db/src/system/path.rs @@ -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 {