[issue43751] await anext() returns None when default is given

2021-04-11 Thread PEW's Corner


PEW's Corner  added the comment:

Thanks!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-10 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset dfb45323ce8a543ca844c311e32c994ec9554c1b by Dennis Sweeney in 
branch 'master':
bpo-43751: Fix anext() bug where it erroneously returned None (GH-25238)
https://github.com/python/cpython/commit/dfb45323ce8a543ca844c311e32c994ec9554c1b


--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-08 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
priority: normal -> release blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-08 Thread Joshua Bronson


Change by Joshua Bronson :


--
nosy: +jab

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Okay, the PR should fix those problems now.

I am still apprehensive about whether all of the corner cases are covered, so 
reviews are welcome, as are suggestions of more test cases.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-07 Thread PEW's Corner


PEW's Corner  added the comment:

Regarding the custom async iterator, I don't know if this is the problem you're 
referring to, but the following code seems to terminate abruptly when running 
main2() (main1() is fine). This is without your changes, though.

import asyncio

class CustomAsyncIter:
def __init__(self):
self.iterator = iter(['A', 'B'])
def __aiter__(self):
return self
async def __anext__(self):
try:
x = next(self.iterator)
except StopIteration:
raise StopAsyncIteration from None
await asyncio.sleep(1)
return x

async def main1():
iter1 = CustomAsyncIter()
print(await anext(iter1))   # Prints 'A'
print(await anext(iter1))   # Prints 'B'
print(await anext(iter1))   # Raises StopAsyncIteration

async def main2():
iter1 = CustomAsyncIter()
print('Before') # Prints 'Before'
print(await anext(iter1, 'Z'))  # Silently terminates the script!!!
print('After')  # This never gets executed

asyncio.run(main2())

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-06 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

That change fixes that bug, but I think there may be another bug involving when 
a custom async iterator is passed rather than an async generator. This is at 
the limit of my knowledge, so any guidance would be appreciated. The test I 
wrote in the PR currently fails, due to some `tp_iternext` slot being NULL 
sometimes. Maybe different cases are needed for Coroutine/non-Coroutine?

But it definitely seems like the aiter()/anext() code needs more test coverage.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-06 Thread Dennis Sweeney


Change by Dennis Sweeney :


--
keywords: +patch
pull_requests: +23976
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25238

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-06 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I can open a PR this evening, but I think this is close to the issue: 
PyIter_Next() already silences StopIteration, so checking for it afterward 
fails.

diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index f0c6b79917..95f4659dc9 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -316,7 +316,7 @@ anextawaitable_traverse(anextawaitableobject *obj, 
visitproc visit, void *arg)
 static PyObject *
 anextawaitable_iternext(anextawaitableobject *obj)
 {
-PyObject *result = PyIter_Next(obj->wrapped);
+PyObject *result = (*Py_TYPE(obj->wrapped)->tp_iternext)(obj->wrapped);
 if (result != NULL) {
 return result;
 }

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43751] await anext() returns None when default is given

2021-04-06 Thread PEW's Corner


New submission from PEW's Corner :

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com