Message390349
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. |
|
| Date |
User |
Action |
Args |
| 2021-04-06 16:00:14 | pewscorner | set | recipients:
+ pewscorner, asvetlov, yselivanov |
| 2021-04-06 16:00:14 | pewscorner | set | messageid: <1617724814.14.0.517501509303.issue43751@roundup.psfhosted.org> |
| 2021-04-06 16:00:14 | pewscorner | link | issue43751 messages |
| 2021-04-06 16:00:14 | pewscorner | create | |
|