mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-28 23:43:53 +00:00
Replace .map_or(false, $closure)
with .is_some_and(closure)
(#6244)
**Summary** [Option::is_some_and](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.is_some_and) and [Result::is_ok_and](https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok_and) are new methods is rust 1.70. I find them way more readable than `.map_or(false, ...)`. The changes are `s/.map_or(false,/.is_some_and(/g`, then manually switching to `is_ok_and` where the value is a Result rather than an Option. **Test Plan** n/a^
This commit is contained in:
parent
2e1754e5fc
commit
1df7e9831b
162 changed files with 344 additions and 476 deletions
|
@ -5,10 +5,7 @@ use crate::keyword::is_keyword;
|
|||
pub fn is_identifier(name: &str) -> bool {
|
||||
// Is the first character a letter or underscore?
|
||||
let mut chars = name.chars();
|
||||
if !chars
|
||||
.next()
|
||||
.map_or(false, |c| c.is_alphabetic() || c == '_')
|
||||
{
|
||||
if !chars.next().is_some_and(|c| c.is_alphabetic() || c == '_') {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -41,7 +38,7 @@ pub fn is_module_name(name: &str) -> bool {
|
|||
let mut chars = name.chars();
|
||||
if !chars
|
||||
.next()
|
||||
.map_or(false, |c| c.is_ascii_lowercase() || c == '_')
|
||||
.is_some_and(|c| c.is_ascii_lowercase() || c == '_')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -3,23 +3,23 @@ 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")
|
||||
.is_some_and(|ext| ext == "py" || ext == "pyi")
|
||||
}
|
||||
|
||||
/// Return `true` if the [`Path`] is named `pyproject.toml`.
|
||||
pub fn is_project_toml(path: &Path) -> bool {
|
||||
path.file_name()
|
||||
.map_or(false, |name| name == "pyproject.toml")
|
||||
.is_some_and(|name| name == "pyproject.toml")
|
||||
}
|
||||
|
||||
/// 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")
|
||||
path.extension().is_some_and(|ext| ext == "pyi")
|
||||
}
|
||||
|
||||
/// Return `true` if the [`Path`] appears to be that of a Jupyter notebook (`.ipynb`).
|
||||
pub fn is_jupyter_notebook(path: &Path) -> bool {
|
||||
path.extension().map_or(false, |ext| ext == "ipynb")
|
||||
path.extension().is_some_and(|ext| ext == "ipynb")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue