This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: yield unpacking
Type: enhancement Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Mital Ashok, ethan.furman, josh.r
Priority: normal Keywords:

Created on 2015-05-29 18:23 by Mital Ashok, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg244397 - (view) Author: Mital Ashok (Mital Ashok) * Date: 2015-05-29 18:23
(This is more of a feature request than a bug, but https://www.python.org/dev/peps/pep-0042/ said to post it here)

My request is to have syntax like this:

    yield *iterable

to lazily return the iterable's items, not much unlike:

    # ...
    for i in iterable:
        yield i
    # ...

This is because I constantly find myself yielding all the values in, say, a list, then modifying it and yielding it in a loop.
msg244398 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-05-29 18:32
Do you mean something like:

--> def heh():
...   yield [1, 2, 3]
... 
--> for i in heh():
...   print(i)
... 
[1, 2, 3]
# *grumble*
--> def heh():
...   for i in [1, 2, 3]:
...     yield i
... 
--> for i in heh():
...   print(i)
... 
1
2
3


If so, use `yield from`:

--> def huh():
...   yield from [1, 2, 3]
... 
--> for i in huh():
...   print(i)
... 
1
2
3
msg244461 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2015-05-30 15:02
Should someone be closing this with "yield from already exists"?
msg244472 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-05-30 16:48
I was waiting a couple days to give Mital a chance to clarify if some other behavior was intended.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68515
2015-05-30 16:48:24ethan.furmansetmessages: + msg244472
2015-05-30 15:03:57serhiy.storchakasetstatus: open -> closed
resolution: out of date
stage: resolved
2015-05-30 15:02:51josh.rsetnosy: + josh.r
messages: + msg244461
2015-05-29 18:32:49ethan.furmansetnosy: + ethan.furman
messages: + msg244398
2015-05-29 18:23:02Mital Ashokcreate