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

Fix asyncio executor types #13616

Merged
merged 3 commits into from
Mar 11, 2025
Merged

Conversation

max-muoto
Copy link
Contributor

@max-muoto max-muoto commented Mar 11, 2025

This PR:

  • Moves away from Any in run_in_executor, which should be Executor | None. See docs here. The default executor is used if None is specifically provided. We're doing this both in the concrete BaseEventLoop and the AbstractEventLoop.
  • Moves to ThreadPoolExecutor as the sole argument annotation for set_default_executor on BaseEventLoop. Technically we could type this as Executor in prior versions however considering passing non thread-pool executors as arguments has been deprecated since 3.8 I don't see any value in adding a deprecated pre 3.11 overload.
  • Moves to Executor as the sole argument annotation for set_default_executor on AbstractEventLoop. Despite breaking the liskov substitution principle it seems valuable to me to maintain the fact that third party libraries are able to use non thread pool executors in their own custom event loops, open to changing this however.

max-muoto and others added 3 commits March 11, 2025 00:27
Update type annotations for `run_in_executor` and `set_default_executor` in asyncio event loop interfaces to use more specific executor types from `concurrent.futures`
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
Copy link
Collaborator

srittau commented Mar 11, 2025

CI failures are unrelated.

@srittau srittau merged commit 2e76963 into python:main Mar 11, 2025
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants