mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
Python: UnguardedNextInGenerator.ql: Excludes next with default value
This commit is contained in:
@@ -28,6 +28,10 @@ predicate call_to_next(CallNode call, ControlFlowNode iter) {
|
||||
iter = next().getArgumentForCall(call, 0)
|
||||
}
|
||||
|
||||
predicate call_to_next_has_default(CallNode call) {
|
||||
exists(call.getArg(1))
|
||||
}
|
||||
|
||||
predicate guarded_not_empty_sequence(EssaVariable sequence) {
|
||||
sequence.getDefinition() instanceof EssaEdgeRefinement
|
||||
}
|
||||
@@ -49,6 +53,7 @@ predicate stop_iteration_handled(CallNode call) {
|
||||
|
||||
from CallNode call
|
||||
where call_to_next(call, _) and
|
||||
not call_to_next_has_default(call) and
|
||||
not exists(EssaVariable iterator |
|
||||
call_to_next(call, iterator.getAUse()) and
|
||||
iter_not_exhausted(iterator)
|
||||
|
||||
@@ -47,3 +47,6 @@ def next_in_comp(seq, fields):
|
||||
seq_iter = iter(seq)
|
||||
values = [ next(seq_iter) if f.attname in NAMES else DEFAULT for f in fields ]
|
||||
return values
|
||||
|
||||
def ok5(seq):
|
||||
yield next(iter([]), 'foo')
|
||||
|
||||
Reference in New Issue
Block a user