Skip to content
Draft
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
20 changes: 18 additions & 2 deletions src/executorlib/standalone/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FutureSelector(Future):
the desired element from the result.
"""

def __init__(self, future: Future, selector: int | str):
def __init__(self, future: Future[Any], selector: int | str):
"""
Args:
future (Future): The underlying future whose result is a collection.
Expand Down Expand Up @@ -50,7 +50,23 @@ def result(self, timeout: Optional[float] = None) -> Any:
"""
result = self._future.result(timeout=timeout)
if result is not None:
return result[self._selector]
if (
isinstance(self._selector, int)
and isinstance(result, (tuple, list))
or isinstance(result, dict)
and self._selector in result
):
return result[self._selector]
else:
raise KeyError(
str(self._selector)
+ " of type "
+ str(type(self._selector))
+ " is not in "
+ str(result)
+ " of type "
+ str(type(result))
)
else:
return None

Expand Down
Loading