New submission from PEW's Corner <pewscor...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue43751>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to