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
asyncio.as_completed documentation misleading #84585
Comments
Continuing with bpo-27589, looks like as_completed documentation is still misleading. According to the docs, it "Return(s) an iterator of Future objects. Each Future object returned represents the earliest result from the set of the remaining awaitables." There's only one problem: The only thing it definitely doesn't do, is return an iterator of future objects. To be honest with you, I'm not entirely sure how to phrase it. For reference, I fell for this: mapping = {fut: index for fut, index in enumerate(futures)}
for fut in as_completed(mapping):
mapping[fut] # KeyError |
I declare this not a bug. The docs do not promise that the Futures being returned are the *same* Futures that were passed in. They are not. They are (or at least may be) new Futures that represent the same event. Since Futures, when used as dict keys, use identity as equality, those new Futures will not be present as keys in the mapping of Futures passed in by the OP. |
Reopening so as to give the OP one more chance to state their case. They wrote: """ If it's not a Future then what? You're not showing that in your report. |
It's a coroutine. Basically the same coroutine yielded over and over, returning the first future's result each time. |
Oh, you're right. The docstring correctly says this. :-( Do you have the power to submit a PR? I think it should just say that the return values are coroutines (which is what it does). @yury what do you think? |
Yeah, the documentation needs to be fixed.
I'd suggest to change to: "Return an iterator of coroutines. Each coroutine allows to wait for the earliest next result from the set of the remaining awaitables." |
Yury Selivanov wrote:
The first sentence looks good to me, but I'm not certain about the second sentence, particularly "allows to wait". Instead, I'm thinking something like this might read better: "Each coroutine represents the earliest next result from the set of the remaining awaitables, based upon the order of completion." Thoughts? |
I forgot to explain this in the above message. I think something that mentions "order of completion" should be included. Although it's implied in the name |
Alternatively, I think "can wait for" would also read better than "allows to wait for", if that is preferred over my above suggestion. |
Please work this out in the PR between the two of you, Kyle and Bar. |
@kyle, looks good to me. Maybe this will work better? Together with the current example which shows the "earliest_result" variable of course. "Each coroutine returns the next result from the set of the remaining awaitables, based upon the order of completion." Represents -> Returns (less obscure, and coroutines are awaited on to get the result) |
@bar as requested by Guido, let's continue the discussion in the PR: #19753 (review). |
Thanks for bring this to our attention and working on this Bar Harel, and thanks to Yury for the suggestions. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: