mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-23 10:32:49 +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`.
|
||||
fn is_alias(expr: &Expr, semantic: &SemanticModel) -> bool {
|
||||
semantic.resolve_call_path(expr).map_or(false, |call_path| {
|
||||
ALIASES
|
||||
.iter()
|
||||
.any(|(module, member)| call_path.as_slice() == [*module, *member])
|
||||
matches!(
|
||||
call_path.as_slice(),
|
||||
["", "EnvironmentError" | "IOError" | "WindowsError"]
|
||||
| ["mmap" | "select" | "socket", "error"]
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue