Skip to content

Commit 3e46604

Browse files
authored
Merge pull request github#3223 from BekaValentine/python-objectapi-to-valueapi-iterreturnsnoniterator
Python: ObjectAPI to ValueAPI: IterReturnsNonIterator
2 parents d9a2429 + 7a586c9 commit 3e46604

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

python/ql/src/Functions/IterReturnsNonIterator.ql

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,10 @@
1212

1313
import python
1414

15-
ClassObject return_type(FunctionObject f) {
16-
exists(ControlFlowNode n, Return ret |
17-
ret.getScope() = f.getFunction() and
18-
ret.getValue() = n.getNode() and
19-
n.refersTo(_, result, _)
20-
)
21-
}
22-
23-
from ClassObject iterable, FunctionObject iter, ClassObject iterator
15+
from ClassValue iterable, FunctionValue iter, ClassValue iterator
2416
where
25-
iter = iterable.lookupAttribute("__iter__") and
26-
iterator = return_type(iter) and
17+
iter = iterable.lookup("__iter__") and
18+
iterator = iter.getAnInferredReturnType() and
2719
not iterator.isIterator()
2820
select iterator,
2921
"Class " + iterator.getName() +
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| file://:Compiled Code:0:0:0:0 | builtin-class object | Class object is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:16:5:16:23 | Function __iter__ | __iter__ |
2-
| protocols.py:20:1:20:26 | class IteratorMissingNext | Class IteratorMissingNext is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:22:5:22:23 | Function __iter__ | __iter__ |
3-
| protocols.py:20:1:20:26 | class IteratorMissingNext | Class IteratorMissingNext is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:27:5:27:23 | Function __iter__ | __iter__ |
4-
| protocols.py:30:1:30:26 | class IteratorMissingIter | Class IteratorMissingIter is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:40:5:40:23 | Function __iter__ | __iter__ |
1+
| file://:0:0:0:0 | builtin-class object | Class object is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:16:5:16:23 | Function X.__iter__ | __iter__ |
2+
| protocols.py:20:1:20:26 | class IteratorMissingNext | Class IteratorMissingNext is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:22:5:22:23 | Function IteratorMissingNext.__iter__ | __iter__ |
3+
| protocols.py:20:1:20:26 | class IteratorMissingNext | Class IteratorMissingNext is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:27:5:27:23 | Function IterableMissingNext.__iter__ | __iter__ |
4+
| protocols.py:30:1:30:26 | class IteratorMissingIter | Class IteratorMissingIter is returned as an iterator (by $@) but does not fully implement the iterator interface. | protocols.py:40:5:40:23 | Function IterableMissingIter.__iter__ | __iter__ |

0 commit comments

Comments
 (0)