-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add better types for asyncio.gather #9678
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
Conversation
This comment has been minimized.
This comment has been minimized.
Looking at #9105 I don't think the case presented where you have vargs of different types actually happens that much whereas unpacking as shown in the screenshots above is much more common and helps catch errors that would have gone amiss. |
This looks promising. The Some of the test cases in https://github.com/python/typeshed/blob/main/test_cases/stdlib/asyncio/check_gather.py are failing, and will need to be updated. Lastly, as well as adding the new overload, we should probably also update the existing fallback overloads here to be more precise as well: typeshed/stdlib/asyncio/tasks.pyi Lines 142 to 143 in cd5f976
typeshed/stdlib/asyncio/tasks.pyi Lines 232 to 235 in cd5f976
They should probably be changed to: @overload
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: bool) -> Future[list[_T | BaseException]]: ... # type: ignore[misc] |
home-assistant/core@04e05af/homeassistant/components/amcrest/camera.py#L404-L418 would be inferred as list[str | bool] but I guess that can be solved as you said by adding another overload. |
This comment has been minimized.
This comment has been minimized.
I don't think this is gonna work (with pyright at least) cause adding a special case for the 0 arg call (which is required to avoid the return of |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
All of the failures look like mypy bugs and the failure in pyright is IMO acceptable I just don't know what the test needs to be changed to to pass |
Hmm the paasta things seem like they do now break which is annoying. I'm not entirely sure what's wrong there though. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This seems to me like it should now work, |
This comment has been minimized.
8000
This comment has been minimized.
8000There 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.
LGTM
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.
This looks great, thanks for persevering with this! Pushed one more test just to be safe.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Before:

After:
