Update tests

This commit is contained in:
Joe Farebrother
2025-05-23 13:04:56 +01:00
parent f27057a747
commit 06504f2cb6
5 changed files with 44 additions and 1 deletions

View File

@@ -2,5 +2,6 @@ ql/python/ql/src/Functions/NonCls.ql
ql/python/ql/src/Functions/NonSelf.ql
ql/python/ql/src/Functions/ReturnConsistentTupleSizes.ql
ql/python/ql/src/Functions/SignatureSpecialMethods.ql
ql/python/ql/src/Functions/IterReturnsNonSelf.ql
ql/python/ql/src/Resources/FileNotAlwaysClosed.ql
ql/python/ql/src/Variables/LoopVariableCapture/LoopVariableCapture.ql

View File

@@ -1 +0,0 @@
| protocols.py:54:1:54:29 | class AlmostIterator | Class AlmostIterator is an iterator but its $@ method does not return 'self'. | protocols.py:62:5:62:23 | Function __iter__ | __iter__ |

View File

@@ -0,0 +1,43 @@
class Bad1:
def __next__(self):
return 0
def __iter__(self): # BAD: Iter does not return self
yield 0
class Good1:
def __next__(self):
return 0
def __iter__(self): # GOOD: iter returns self
return self
class Good2:
def __init__(self):
self._it = iter([0,0,0])
def __next__(self):
return next(self._it)
def __iter__(self): # GOOD: iter and next are wrappers around a field
return self._it.__iter__()
class Good3:
def __next__(self):
return 0
def __iter__(self): # GOOD: this is an equivalent iterator to `self`.
return iter(self.__next__, None)
class FalsePositive1:
def __init__(self):
self._it = None
def __next__(self):
if self._it is None:
self._it = iter(self)
return next(self._it)
def __iter__(self): # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.
yield 0
yield 0