-
Notifications
You must be signed in to change notification settings - Fork 3
FutureSelector: More generic interface to concurrent.futures.Future #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,24 +4,18 @@ | |||||||||||
|
|
||||||||||||
| class FutureSelector(Future): | ||||||||||||
| def __init__(self, future: Future, selector: int | str): | ||||||||||||
| super().__init__() | ||||||||||||
| self._future = future | ||||||||||||
| self._selector = selector | ||||||||||||
| super().__init__() | ||||||||||||
|
|
||||||||||||
| def cancel(self) -> bool: | ||||||||||||
| return self._future.cancel() | ||||||||||||
|
|
||||||||||||
| def cancelled(self) -> bool: | ||||||||||||
| return self._future.cancelled() | ||||||||||||
|
|
||||||||||||
| def running(self) -> bool: | ||||||||||||
| return self._future.running() | ||||||||||||
|
|
||||||||||||
| def done(self) -> bool: | ||||||||||||
| return self._future.done() | ||||||||||||
| def __getattr__(self, attr: str) -> Any: | ||||||||||||
| return getattr(self._future, attr) | ||||||||||||
|
|
||||||||||||
| def add_done_callback(self, fn) -> None: | ||||||||||||
| return self._future.add_done_callback(fn=fn) | ||||||||||||
| def __setattr__(self, name: str, value: Any): | ||||||||||||
| if name in ["_future", "_selector"]: | ||||||||||||
| super().__setattr__(name, value) | ||||||||||||
| else: | ||||||||||||
| setattr(self._future, name, value) | ||||||||||||
|
Comment on lines
+14
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove setattr: it corrupts Future internals This forwards assignments like _state/_condition to the inner future, breaking the wrapper’s own Future state and callback machinery. Apply this diff to drop it: - def __setattr__(self, name: str, value: Any):
- if name in ["_future", "_selector"]:
- super().__setattr__(name, value)
- else:
- setattr(self._future, name, value)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| def result(self, timeout: Optional[float] = None) -> Any: | ||||||||||||
| result = self._future.result(timeout=timeout) | ||||||||||||
|
|
@@ -30,18 +24,6 @@ def result(self, timeout: Optional[float] = None) -> Any: | |||||||||||
| else: | ||||||||||||
| return None | ||||||||||||
|
|
||||||||||||
| def exception(self, timeout: Optional[float] = None) -> Optional[BaseException]: | ||||||||||||
| return self._future.exception(timeout=timeout) | ||||||||||||
|
|
||||||||||||
| def set_running_or_notify_cancel(self) -> bool: | ||||||||||||
| return self._future.set_running_or_notify_cancel() | ||||||||||||
|
|
||||||||||||
| def set_result(self, result: Any) -> None: | ||||||||||||
| return self._future.set_result(result=result) | ||||||||||||
|
|
||||||||||||
| def set_exception(self, exception: Optional[BaseException]) -> None: | ||||||||||||
| return self._future.set_exception(exception=exception) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def split_future(future: Future, n: int) -> list[FutureSelector]: | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Sanity checks before merge
Run a quick repo scan for potential coupling to the previous delegation behavior:
Also applies to: 28-39, 42-55
🏁 Script executed:
Length of output: 12653
Sanity checks before merge — fix FutureSelector delegation
🤖 Prompt for AI Agents