mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
Update tests
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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__ |
|
||||
43
python/ql/test/query-tests/Functions/iterators/test.py
Normal file
43
python/ql/test/query-tests/Functions/iterators/test.py
Normal 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
|
||||
Reference in New Issue
Block a user