diff options
author | Jeff Widman <jeff@jeffwidman.com> | 2017-10-18 20:28:21 -0700 |
---|---|---|
committer | Jeff Widman <jeff@jeffwidman.com> | 2017-10-18 20:39:04 -0700 |
commit | 95d33e0846484950313475ca6eb6ac523b23ade2 (patch) | |
tree | 862313378ecb6b081fa37c2cb93ffdd24b918448 | |
parent | 13752d74ef6d4c947146899668fa41c6a317bb3f (diff) | |
download | kafka-python-check-for-none-rather-than-false.tar.gz |
Explicitly check for None rather than falseycheck-for-none-rather-than-false
Be pedantic about checking for identity rather than equality to avoid issues like #1237 / 411bc08f214b7afc36f11bde2047096c06467088
-rw-r--r-- | kafka/client_async.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/kafka/client_async.py b/kafka/client_async.py index f6fe829..dbfcdcb 100644 --- a/kafka/client_async.py +++ b/kafka/client_async.py @@ -539,7 +539,7 @@ class KafkaClient(object): task_future.success(result) # If we got a future that is already done, don't block in _poll - if future and future.is_done: + if future is not None and future.is_done: timeout = 0 else: idle_connection_timeout_ms = self._idle_expiry_manager.next_check_ms() @@ -555,7 +555,7 @@ class KafkaClient(object): # If all we had was a timeout (future is None) - only do one poll # If we do have a future, we keep looping until it is done - if not future or future.is_done: + if future is None or future.is_done: break return responses @@ -660,7 +660,7 @@ class KafkaClient(object): conn = self._conns.get(node_id) connected = conn is not None and conn.connected() blacked_out = conn is not None and conn.blacked_out() - curr_inflight = len(conn.in_flight_requests) if conn else 0 + curr_inflight = len(conn.in_flight_requests) if conn is not None else 0 if connected and curr_inflight == 0: # if we find an established connection # with no in-flight requests, we can stop right away @@ -681,8 +681,6 @@ class KafkaClient(object): elif 'bootstrap' in self._conns: return 'bootstrap' - return None - def set_topics(self, topics): """Set specific topics to track for metadata. |