Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/io/requestresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def process(self, request: RequestT, *args, **kwargs):
response = self._repeater.repeat(
self._caller, request, self._timeout, self._metrics_collector)
self._metrics_collector.responses.inc(1)
self._throttler.throttler.successful_request(req_time * MSEC_TO_SEC)
if self._throttler:
self._throttler.throttler.successful_request(req_time * MSEC_TO_SEC)
Comment on lines +378 to +379

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to PEP 8, comparisons to singletons like None should always be done with is or is not, never the equality operators or implicit truthiness checks, especially when testing whether an optional variable or argument that defaults to None was set. Using is not None is safer and more explicit.

Suggested change
if self._throttler:
self._throttler.throttler.successful_request(req_time * MSEC_TO_SEC)
if self._throttler is not None:
self._throttler.throttler.successful_request(req_time * MSEC_TO_SEC)
References
  1. PEP 8: Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Also, beware of writing 'if x' when you really mean 'if x is not None'. (link)

yield response
except Exception as e:
raise e
Expand Down
Loading