ruff: Fix B012 return inside finally blocks.

return inside finally blocks causes exceptions to be silenced.
Although these blocks follow blanket ‘except Exception’ handlers, they
do not seem to have a goal of silencing BaseException and exceptions
thrown by the exception handler, so rewrite them to avoid it.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-11-15 21:04:34 -08:00 committed by Tim Abbott
parent c4e5ddd67f
commit 1735b8863e
2 changed files with 11 additions and 11 deletions

View File

@ -208,7 +208,7 @@ class ClientDescriptor:
) )
finally: finally:
self.disconnect_handler() self.disconnect_handler()
return True return True
return False return False
def accepts_event(self, event: Mapping[str, Any]) -> bool: def accepts_event(self, event: Mapping[str, Any]) -> bool:

View File

@ -339,16 +339,16 @@ class QueueProcessingWorker(ABC):
# especially since the queue might go idle until new events come in. # especially since the queue might go idle until new events come in.
self.update_statistics() self.update_statistics()
self.idle = True self.idle = True
return else:
self.consume_iteration_counter += 1
self.consume_iteration_counter += 1 if (
if ( self.consume_iteration_counter
self.consume_iteration_counter >= self.CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM >= self.CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM
or time.time() - self.last_statistics_update_time or time.time() - self.last_statistics_update_time
>= self.MAX_SECONDS_BEFORE_UPDATE_STATS >= self.MAX_SECONDS_BEFORE_UPDATE_STATS
): ):
self.consume_iteration_counter = 0 self.consume_iteration_counter = 0
self.update_statistics() self.update_statistics()
def consume_single_event(self, event: Dict[str, Any]) -> None: def consume_single_event(self, event: Dict[str, Any]) -> None:
consume_func = lambda events: self.consume(events[0]) consume_func = lambda events: self.consume(events[0])