Now I'm studying on the differences between a yield-from and an await syntax. From the official python documentation, the yield-from generator() is just a syntax suger of the following code:
for i in generator(): yield i
But I can't desugar the yield-from in the example below.
def accumlate():
# context
accumlator = 0
while True:
next = yield
if next is None:
return accumlator
accumlator += next
def gather(tallies):
while True:
tally = yield from accumlate() # (*)
tallies.append(tally)
def main():
tallies = []
accumlator = gather(tallies)
next(accumlator)
for i in range(4):
accumlator.send(i)
accumlator.send(None)
for i in range(6, 10):
accumlator.send(i)
accumlator.send(None)
print(tallies)
if __name__ == "__main__":
main()
I tried to just replace a yield-from with the for-in version, but it did't work because the for-in can't be placed on the right side of the tally variable. What is an exact desugar of the code marked with asterisk ?