Skip to content

Commit 39d942a

Browse files
committed
raise StopIteration because it is clearer than checking for None
1 parent 8aacefb commit 39d942a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

adaptive/runner.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656

5757
def _key_by_value(dct, value):
58-
return next((k for k, v in dct.items() if v == value), None)
58+
return next(k for k, v in dct.items() if v == value)
5959

6060

6161
class BaseRunner(metaclass=abc.ABCMeta):
@@ -248,9 +248,9 @@ def _get_futures(self):
248248
fut = self._submit(x)
249249
fut.start_time = start_time
250250
self.pending_points[fut] = x
251-
i = _key_by_value(self._index_to_point, x) # O(N)
252-
if i is None:
253-
# `x` is not a value in `self._index_to_point`
251+
try:
252+
i = _key_by_value(self._index_to_point, x) # O(N)
253+
except StopIteration: # `x` is not a value in `self._index_to_point`
254254
self._i += 1
255255
i = self._i
256256
self._index_to_point[i] = x

0 commit comments

Comments
 (0)