Skip to content

Conversation

@pgrayy
Copy link
Member

@pgrayy pgrayy commented Dec 17, 2025

Description

Removing another Python 3.11+ feature from bidi. Specifically, removing the asyncio task.cancelling call. This call was used in determining how to propagate asyncio.CancelledErrors in our _TaskGroup implementation.

Note, this PR is part of a larger effort to add Python 3.10 and 3.11 support to bidi. The final PR for this work is currently in draft here.

Related Issues

#1299

Documentation PR

N/A

Type of Change

Other (please describe): Compatibility update.

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare
  • I ran hatch run bidi:prepare: Relying on both existing and new unit tests
  • I ran hatch run bidi-test:test tests_integ/bidi

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Attributes:
_tasks: List of tasks in group.
_tasks: Set of tasks in group.
Copy link
Member Author

Choose a reason for hiding this comment

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

Switching to set to be consistent with asyncio.wait which puts done_tasks and pending_tasks into sets. This in turn helps to resolve a mypy error.

- The context re-raises Exceptions to the caller.
- The context re-raises CancelledErrors to the caller only if the context itself was cancelled.
"""
try:
Copy link
Member Author

@pgrayy pgrayy Dec 17, 2025

Choose a reason for hiding this comment

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

We have the execution rules listed above in the docstring. To repeat here:

"""Execute tasks in group.

The following execution rules are enforced:
- The context stops executing all tasks if at least one task raises an Exception or the context is cancelled.
- The context re-raises Exceptions to the caller.
- The context re-raises CancelledErrors to the caller only if the context itself was cancelled.
"""

await asyncio.gather(*self._tasks)
pending_tasks = self._tasks
while pending_tasks:
done_tasks, pending_tasks = await asyncio.wait(pending_tasks, return_when=asyncio.FIRST_EXCEPTION)
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we reassign pending_tasks which led mypy to complain about set[Task] vs list[Task] and thus why I switched self._tasks to set[Task].

@github-actions github-actions bot added size/s and removed size/s labels Dec 17, 2025
@pgrayy pgrayy deployed to auto-approve December 17, 2025 21:58 — with GitHub Actions Active
@pgrayy pgrayy marked this pull request as ready for review December 17, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant