mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-24 19:12:44 +00:00
Use matches for os-error-alias
(#5361)
This commit is contained in:
parent
fd0c3faa70
commit
19c221a2d2
1 changed files with 5 additions and 12 deletions
|
@ -54,21 +54,14 @@ impl AlwaysAutofixableViolation for OSErrorAlias {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ALIASES: &[(&str, &str)] = &[
|
|
||||||
("", "EnvironmentError"),
|
|
||||||
("", "IOError"),
|
|
||||||
("", "WindowsError"),
|
|
||||||
("mmap", "error"),
|
|
||||||
("select", "error"),
|
|
||||||
("socket", "error"),
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Return `true` if an [`Expr`] is an alias of `OSError`.
|
/// Return `true` if an [`Expr`] is an alias of `OSError`.
|
||||||
fn is_alias(expr: &Expr, semantic: &SemanticModel) -> bool {
|
fn is_alias(expr: &Expr, semantic: &SemanticModel) -> bool {
|
||||||
semantic.resolve_call_path(expr).map_or(false, |call_path| {
|
semantic.resolve_call_path(expr).map_or(false, |call_path| {
|
||||||
ALIASES
|
matches!(
|
||||||
.iter()
|
call_path.as_slice(),
|
||||||
.any(|(module, member)| call_path.as_slice() == [*module, *member])
|
["", "EnvironmentError" | "IOError" | "WindowsError"]
|
||||||
|
| ["mmap" | "select" | "socket", "error"]
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue