Skip to content

Commit

Permalink
Avoid removing parentheses on ctypes.WinError (#9027)
Browse files Browse the repository at this point in the history
Re-resolves #6730.
  • Loading branch information
charliermarsh authored Dec 6, 2023
1 parent ef7778d commit b918647
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/flake8_raise/RSE102.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ def error():

# RSE102
raise Foo()

# OK
raise ctypes.WinError()


def func():
pass


# OK
raise func()
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr:

// `ctypes.WinError()` is a function, not a class. It's part of the standard library, so
// we might as well get it right.
if exception_type
.as_ref()
.is_some_and(ExceptionType::is_builtin)
if exception_type.is_none()
&& checker
.semantic()
.resolve_call_path(func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ RSE102.py:84:10: RSE102 [*] Unnecessary parentheses on raised exception
83 | # RSE102
84 | raise Foo()
| ^^ RSE102
85 |
86 | # OK
|
= help: Remove unnecessary parentheses

Expand All @@ -275,5 +277,8 @@ RSE102.py:84:10: RSE102 [*] Unnecessary parentheses on raised exception
83 83 | # RSE102
84 |-raise Foo()
84 |+raise Foo
85 85 |
86 86 | # OK
87 87 | raise ctypes.WinError()


0 comments on commit b918647

Please sign in to comment.