mirror of https://github.com/astral-sh/ruff
fixup
This commit is contained in:
parent
793d0d0dd4
commit
7ef86c9637
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue