Skip to content
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

Use deterministic version of asyncio.wait #116

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
5 changes: 3 additions & 2 deletions workers/python/kitchen_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ async def run_action(action: Action) -> None:
should_return_task = asyncio.create_task(
workflow.wait_condition(lambda: return_value is not None)
)
done, _ = await asyncio.wait(
# mypy cannot handle the heterogeneous arguments to `wait`
done, _ = await workflow.wait(
[gather_fut, should_return_task], return_when=asyncio.FIRST_COMPLETED
) # type: ignore
for fut in done:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Annoyingly, mypy doesn't infer that done is awaitable here. Not sure why that's not causing lint errors in the SDK (e.g. tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kitchen_sink.py:105: error: Incompatible types in "await" (actual type "object", expected type "Awaitable[Any]")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Investigated a bit. The problem is the heterogenous arguments (an asyncio.Future and an asyncio.Task). mypy cannot handle this, whether for asyncio.wait or for our version of wait, but the wrong inference it makes is slightly different between the two.

await fut
await fut # type: ignore
return return_value

async def handle_action(self, action: Action) -> Optional[Payload]:
Expand Down
Loading