mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Python: Autoformat py/iter-returns-non-iterator
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user