[Python][Part 15] - Introducing Ruff (#40190)

### Description

## Part 15 of Introducing Ruff

* In this PR - the suppression for `TRY002` and `TRY004` has been removed on the root `ruff.toml`

## Related:
* Prev: #40189
* b/423755915

Closes #40190

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/40190 from asheshvidyut:feature/setup-ruff-part-15 9e1c4c2712
PiperOrigin-RevId: 817159922
This commit is contained in:
Ashesh Vidyut
2025-10-09 06:32:21 -07:00
committed by Copybara-Service
parent f4f3e3516e
commit c7cf9cab81
5 changed files with 5 additions and 5 deletions

View File

@@ -88,9 +88,7 @@ ignore = [
"SLOT002", # Subclasses of {namedtuple_kind} should define __slots__
"TC001", # Move application import {} into a type-checking block
"TD003", # Missing issue link for this TODO
"TRY002", # Create your own exception
"TRY003", # Avoid specifying long messages outside the exception class
"TRY004", # Prefer TypeError exception for invalid type
"TRY203", # Remove exception handler; error is immediately re-raised
"TRY300", # Consider moving this statement to an else block
"TRY400", # Use logging.exception instead of logging.error

View File

@@ -458,7 +458,7 @@ class _Context(grpc.ServicerContext):
self._state.code = code
self._state.details = _common.encode(details)
self._state.aborted = True
raise Exception()
raise Exception() # noqa: TRY002
def abort_with_status(self, status: grpc.Status) -> None:
self._state.trailing_metadata = status.trailing_metadata

View File

@@ -358,7 +358,7 @@ class Channel(_base_channel.Channel):
elif isinstance(interceptor, StreamStreamClientInterceptor):
self._stream_stream_interceptors.append(interceptor)
else:
raise ValueError(
raise ValueError( # noqa: TRY004
"Interceptor {} must be ".format(interceptor)
+ "{} or ".format(UnaryUnaryClientInterceptor.__name__)
+ "{} or ".format(UnaryStreamClientInterceptor.__name__)

View File

@@ -57,6 +57,8 @@ class Server(_base_server.Server):
"Interceptor must be ServerInterceptor,"
"the following are invalid: {invalid_interceptors}"
)
# TODO(asheshvidyut): fix the value error below
# not caught by ruff.
raise ValueError(error_msg)
self._server = cygrpc.AioServer(
self._loop,

View File

@@ -75,7 +75,7 @@ class ServicerContext(grpc.ServicerContext):
def abort(self, code, details):
with self._rpc._condition:
self._rpc._abort(code, details)
raise Exception()
raise Exception() # noqa: TRY002
def abort_with_status(self, status):
raise NotImplementedError()