12
12
13
13
import python
14
14
15
- FunctionObject iter ( ) {
16
- result = Object :: builtin ( "iter" )
15
+ FunctionValue iter ( ) {
16
+ result = Value :: named ( "iter" )
17
17
}
18
18
19
- BuiltinFunctionObject next ( ) {
20
- result = Object :: builtin ( "next" )
19
+ BuiltinFunctionValue next ( ) {
20
+ result = Value :: named ( "next" )
21
21
}
22
22
23
23
predicate call_to_iter ( CallNode call , EssaVariable sequence ) {
@@ -28,6 +28,10 @@ predicate call_to_next(CallNode call, ControlFlowNode iter) {
28
28
iter = next ( ) .getArgumentForCall ( call , 0 )
29
29
}
30
30
31
+ predicate call_to_next_has_default ( CallNode call ) {
32
+ exists ( call .getArg ( 1 ) ) or exists ( call .getArgByName ( "default" ) )
33
+ }
34
+
31
35
predicate guarded_not_empty_sequence ( EssaVariable sequence ) {
32
36
sequence .getDefinition ( ) instanceof EssaEdgeRefinement
33
37
}
@@ -43,12 +47,13 @@ predicate iter_not_exhausted(EssaVariable iterator) {
43
47
predicate stop_iteration_handled ( CallNode call ) {
44
48
exists ( Try t |
45
49
t .containsInScope ( call .getNode ( ) ) and
46
- t .getAHandler ( ) .getType ( ) .refersTo ( theStopIterationType ( ) )
50
+ t .getAHandler ( ) .getType ( ) .pointsTo ( ClassValue :: stopIteration ( ) )
47
51
)
48
52
}
49
53
50
54
from CallNode call
51
55
where call_to_next ( call , _) and
56
+ not call_to_next_has_default ( call ) and
52
57
not exists ( EssaVariable iterator |
53
58
call_to_next ( call , iterator .getAUse ( ) ) and
54
59
iter_not_exhausted ( iterator )
@@ -58,4 +63,3 @@ not exists(Comp comp | comp.contains(call.getNode())) and
58
63
not stop_iteration_handled ( call )
59
64
60
65
select call , "Call to next() in a generator"
61
-
0 commit comments