Author pewscorner
Recipients asvetlov, pewscorner, yselivanov
Date 2021-04-06.16:00:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1617724814.14.0.517501509303.issue43751@roundup.psfhosted.org>
In-reply-to
Content
The new anext() builtin in Python 3.10.0a7 doesn't seem to work properly when a default value is provided as the second argument. Here's an example:

import asyncio

async def f():
    yield 'A'
    yield 'B'

async def main():
    g = f()
    print(await anext(g, 'Z'))  # Prints 'None' instead of 'A'!!!
    print(await anext(g, 'Z'))  # Prints 'None' instead of 'B'!!!
    print(await anext(g, 'Z'))  # Prints 'Z'
    g = f()
    print(await anext(g))       # Prints 'A'
    print(await anext(g))       # Prints 'B'
    print(await anext(g))       # Raises StopAsyncIteration

asyncio.run(main())

As indicated above, anext() works fine when no default is given (in the second half of main()), but produces None in every iteration when a default is given (in the first half of main()) except when the iterator is exhausted.
History
Date User Action Args
2021-04-06 16:00:14pewscornersetrecipients: + pewscorner, asvetlov, yselivanov
2021-04-06 16:00:14pewscornersetmessageid: <1617724814.14.0.517501509303.issue43751@roundup.psfhosted.org>
2021-04-06 16:00:14pewscornerlinkissue43751 messages
2021-04-06 16:00:14pewscornercreate