Python: Autoformat py/iter-returns-non-iterator

This commit is contained in:
Rasmus Wriedt Larsen
2019-10-16 15:36:03 +02:00
parent 1c79ec550e
commit 6056b457e9

View File

@@ -12,21 +12,23 @@
import python
FunctionObject iter_method(ClassObject t) {
result = t.lookupAttribute("__iter__")
}
FunctionObject iter_method(ClassObject t) { result = t.lookupAttribute("__iter__") }
cached ClassObject return_type(FunctionObject f) {
cached
ClassObject return_type(FunctionObject f) {
exists(ControlFlowNode n, Return ret |
ret.getScope() = f.getFunction() and ret.getValue() = n.getNode() and
ret.getScope() = f.getFunction() and
ret.getValue() = n.getNode() and
n.refersTo(_, result, _)
)
}
from ClassObject t, FunctionObject iter
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()
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()