-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Enhance aiter to support built-in sync iterables #101495
Comments
|
I am very much in favor of this as it would remove the need to pepper the use of the following utility throughout every code base: async def aiter(iterable: Iterable):
for item in iterable:
yield item |
|
As mentioned in the discussion, sprinkling |
|
Is adding |
Feasible, yes. Desirable, no, as that would make every object an asynchronous iterable. |
|
I am -1 on this, to me this feels like an anti pattern and if you are using async generator for sync code then IMO it is wrong design. |
|
Some motivation was provided in the thread, and the current proposal is about changing |
|
Yes, can we change the PR title? |
|
Should this be extended to "async with" which seems very similar to me |
Not in this issue, but perhaps in another. It has different considerations and is completely unrelated to this issue. |
|
It is worth noting that This does however beg me the question: is it |
|
In general, Python’s design is that keyword and operators have clear, simple behaviour ( |
There are potential licensing concerns unless the person who wrote that code for
It's
That's only true if you accept any iterable, async or not, and want it to work in that loop. |
|
The discussion died and I am still strong -1 to this, I suggest anyone interested taking this forward to get agreement on the semantics and work on a possible PEP. Closing as it is not actionable now. |
This sounds like a good compromise, are there any shipping plans to update the built-in |
|
@ericvsmith This is the issue (talking about this in pycon), probably will not open a pretty much duplicate issue of this feature proposal. Will pursue a PEP as per @kumaraditya303's suggestion |
Feature or enhancement
Enhance builtin iterables like list, range with async methods like aiter, anext,...
Pitch
It would allow to use e.g. async list comprehenions on normal lists like:
[_ async for _ in list(range(1,10))]
-> helpful if the code snipped is supposed to handle async iterables like normal iterables
Previous discussion
https://discuss.python.org/t/enhance-builtin-iterables-like-list-range-with-async-methods-like-aiter-anext/21352/1
Linked PRs
The text was updated successfully, but these errors were encountered: