Skip to content

Commit 06504f2

Browse files
Update tests
1 parent f27057a commit 06504f2

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

python/ql/integration-tests/query-suite/python-code-quality.qls.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ ql/python/ql/src/Functions/NonCls.ql
22
ql/python/ql/src/Functions/NonSelf.ql
33
ql/python/ql/src/Functions/ReturnConsistentTupleSizes.ql
44
ql/python/ql/src/Functions/SignatureSpecialMethods.ql
5+
ql/python/ql/src/Functions/IterReturnsNonSelf.ql
56
ql/python/ql/src/Resources/FileNotAlwaysClosed.ql
67
ql/python/ql/src/Variables/LoopVariableCapture/LoopVariableCapture.ql

python/ql/test/query-tests/Functions/general/IterReturnsNonSelf.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/ql/test/query-tests/Functions/iterators/IterReturnsNonSelf.expected

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Bad1:
2+
def __next__(self):
3+
return 0
4+
5+
def __iter__(self): # BAD: Iter does not return self
6+
yield 0
7+
8+
class Good1:
9+
def __next__(self):
10+
return 0
11+
12+
def __iter__(self): # GOOD: iter returns self
13+
return self
14+
15+
class Good2:
16+
def __init__(self):
17+
self._it = iter([0,0,0])
18+
19+
def __next__(self):
20+
return next(self._it)
21+
22+
def __iter__(self): # GOOD: iter and next are wrappers around a field
23+
return self._it.__iter__()
24+
25+
class Good3:
26+
def __next__(self):
27+
return 0
28+
29+
def __iter__(self): # GOOD: this is an equivalent iterator to `self`.
30+
return iter(self.__next__, None)
31+
32+
class FalsePositive1:
33+
def __init__(self):
34+
self._it = None
35+
36+
def __next__(self):
37+
if self._it is None:
38+
self._it = iter(self)
39+
return next(self._it)
40+
41+
def __iter__(self): # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.
42+
yield 0
43+
yield 0

0 commit comments

Comments
 (0)