[New-bugs-announce] [issue43751] await anext() returns None when default is given
PEW's Corner
report at bugs.python.org
Tue Apr 6 12:00:14 EDT 2021
New submission from PEW's Corner <pewscorner at gmail.com>:
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.
----------
components: Interpreter Core, asyncio
messages: 390349
nosy: asvetlov, pewscorner, yselivanov
priority: normal
severity: normal
status: open
title: await anext() returns None when default is given
type: behavior
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43751>
_______________________________________
More information about the New-bugs-announce
mailing list