mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-28 15:33:50 +00:00
Remove AST checker's dependency on resolver (#3368)
This commit is contained in:
parent
074f5634a5
commit
8437399496
8 changed files with 62 additions and 58 deletions
34
crates/ruff_python_stdlib/src/path.rs
Normal file
34
crates/ruff_python_stdlib/src/path.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use std::path::Path;
|
||||
|
||||
/// Return `true` if the [`Path`] appears to be that of a Python file.
|
||||
pub fn is_python_file(path: &Path) -> bool {
|
||||
path.extension()
|
||||
.map_or(false, |ext| ext == "py" || ext == "pyi")
|
||||
}
|
||||
|
||||
/// Return `true` if the [`Path`] appears to be that of a Python interface definition file (`.pyi`).
|
||||
pub fn is_python_stub_file(path: &Path) -> bool {
|
||||
path.extension().map_or(false, |ext| ext == "pyi")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
|
||||
use crate::path::is_python_file;
|
||||
|
||||
#[test]
|
||||
fn inclusions() {
|
||||
let path = Path::new("foo/bar/baz.py");
|
||||
assert!(is_python_file(path));
|
||||
|
||||
let path = Path::new("foo/bar/baz.pyi");
|
||||
assert!(is_python_file(path));
|
||||
|
||||
let path = Path::new("foo/bar/baz.js");
|
||||
assert!(!is_python_file(path));
|
||||
|
||||
let path = Path::new("foo/bar/baz");
|
||||
assert!(!is_python_file(path));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue