Avoid removing parentheses on ctypes.WinError (#9027)

Re-resolves https://github.com/astral-sh/ruff/issues/6730.
This commit is contained in:
Charlie Marsh 2023-12-06 12:05:34 -05:00 committed by GitHub
parent ef7778d794
commit b918647927
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View file

@ -82,3 +82,14 @@ raise IndexError();
# RSE102
raise Foo()
# OK
raise ctypes.WinError()
def func():
pass
# OK
raise func()

View file

@ -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)

View file

@ -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
@ -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()