Python: Improve alert message for py/iter-returns-non-iterator

Fixes https://github.com/Semmle/ql/issues/1427
This commit is contained in:
Rasmus Wriedt Larsen
2019-10-16 15:57:18 +02:00
parent 6056b457e9
commit e487fd3648
2 changed files with 9 additions and 11 deletions

View File

@@ -12,8 +12,6 @@
import python
FunctionObject iter_method(ClassObject t) { result = t.lookupAttribute("__iter__") }
cached
ClassObject return_type(FunctionObject f) {
exists(ControlFlowNode n, Return ret |
@@ -23,12 +21,12 @@ ClassObject return_type(FunctionObject f) {
)
}
from ClassObject t, FunctionObject iter
from ClassObject container, FunctionObject iter, ClassObject iterator
where
exists(ClassObject ret_t |
iter = iter_method(t) and
ret_t = return_type(iter) and
not ret_t.isIterator()
)
select iter, "The '__iter__' method of iterable class $@ does not return an iterator.", t,
t.getName()
iter = container.lookupAttribute("__iter__") and
iterator = return_type(iter) and
not iterator.isIterator()
select iterator,
"Class " + iterator.getName() +
" is returned as an iterator (by $@) but does not fully implement the iterator interface.",
iter, iter.getName()