mirror of https://github.com/astral-sh/ruff
Allow `ctypes.WinError()` in flake8-raise (#6731)
Closes https://github.com/astral-sh/ruff/issues/6730.
This commit is contained in:
parent
83f68891e0
commit
d5a51b4e45
|
|
@ -52,3 +52,10 @@ class Class:
|
||||||
|
|
||||||
# OK
|
# OK
|
||||||
raise Class.error()
|
raise Class.error()
|
||||||
|
|
||||||
|
|
||||||
|
import ctypes
|
||||||
|
|
||||||
|
|
||||||
|
# OK
|
||||||
|
raise ctypes.WinError(1)
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,16 @@ pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `ctypes.WinError()` is a function, not a class. It's part of the standard library, so
|
||||||
|
// we might as well get it right.
|
||||||
|
if checker
|
||||||
|
.semantic()
|
||||||
|
.resolve_call_path(func)
|
||||||
|
.is_some_and(|call_path| matches!(call_path.as_slice(), ["ctypes", "WinError"]))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let range = match_parens(func.end(), checker.locator(), checker.source_type)
|
let range = match_parens(func.end(), checker.locator(), checker.source_type)
|
||||||
.expect("Expected call to include parentheses");
|
.expect("Expected call to include parentheses");
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryParenOnRaiseException, range);
|
let mut diagnostic = Diagnostic::new(UnnecessaryParenOnRaiseException, range);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue