Skip to content

Commit

Permalink
Allow ctypes.WinError() in flake8-raise (#6731)
Browse files Browse the repository at this point in the history
Closes #6730.
  • Loading branch information
charliermarsh authored Aug 21, 2023
1 parent 83f6889 commit d5a51b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/ruff/resources/test/fixtures/flake8_raise/RSE102.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def error():

# OK
raise Class.error()


import ctypes


# OK
raise ctypes.WinError(1)
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr:
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)
.expect("Expected call to include parentheses");
let mut diagnostic = Diagnostic::new(UnnecessaryParenOnRaiseException, range);
Expand Down

0 comments on commit d5a51b4

Please sign in to comment.