mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Python: Add __aiter__ as a recognised iterator method.
This commit is contained in:
@@ -350,6 +350,8 @@ class ClassValue extends Value {
|
||||
predicate isIterable() {
|
||||
this.hasAttribute("__iter__")
|
||||
or
|
||||
this.hasAttribute("__aiter__")
|
||||
or
|
||||
this.hasAttribute("__getitem__")
|
||||
}
|
||||
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user