Python: Add __aiter__ as a recognised iterator method.

This commit is contained in:
Taus Brock-Nannestad
2019-09-23 12:24:32 +02:00
parent 7a57a3c743
commit e1012d8d5a
3 changed files with 30 additions and 0 deletions

View File

@@ -350,6 +350,8 @@ class ClassValue extends Value {
predicate isIterable() {
this.hasAttribute("__iter__")
or
this.hasAttribute("__aiter__")
or
this.hasAttribute("__getitem__")
}

View File

@@ -1 +1,2 @@
| async_iterator.py:26:11:26:34 | For | $@ of class '$@' may be used in for-loop. | async_iterator.py:26:20:26:33 | ControlFlowNode for MissingAiter() | Non-iterator | async_iterator.py:13:1:13:19 | class MissingAiter | MissingAiter |
| statements_test.py:34:5:34:19 | For | $@ of class '$@' may be used in for-loop. | statements_test.py:34:18:34:18 | ControlFlowNode for IntegerLiteral | Non-iterator | file://:0:0:0:0 | builtin-class int | int |

View File

@@ -0,0 +1,27 @@
class AsyncIterator:
def __init__(self):
pass
def __aiter__(self):
return self
async def __anext__(self):
await asyncio.sleep(5)
return 1
class MissingAiter:
def __init__(self, delay, to):
pass
async def __anext__(self):
await asyncio.sleep(5)
return 1
async def good():
async for x in AsyncIterator():
yield x
async def bad():
async for x in MissingAiter():
yield x