1212
1313import python
1414
15- FunctionObject iter ( ) {
16- result = Object :: builtin ( "iter" )
15+ FunctionValue iter ( ) {
16+ result = Value :: named ( "iter" )
1717}
1818
19- BuiltinFunctionObject next ( ) {
20- result = Object :: builtin ( "next" )
19+ BuiltinFunctionValue next ( ) {
20+ result = Value :: named ( "next" )
2121}
2222
2323predicate call_to_iter ( CallNode call , EssaVariable sequence ) {
@@ -28,6 +28,10 @@ predicate call_to_next(CallNode call, ControlFlowNode iter) {
2828 iter = next ( ) .getArgumentForCall ( call , 0 )
2929}
3030
31+ predicate call_to_next_has_default ( CallNode call ) {
32+ exists ( call .getArg ( 1 ) ) or exists ( call .getArgByName ( "default" ) )
33+ }
34+
3135predicate guarded_not_empty_sequence ( EssaVariable sequence ) {
3236 sequence .getDefinition ( ) instanceof EssaEdgeRefinement
3337}
@@ -43,12 +47,13 @@ predicate iter_not_exhausted(EssaVariable iterator) {
4347predicate stop_iteration_handled ( CallNode call ) {
4448 exists ( Try t |
4549 t .containsInScope ( call .getNode ( ) ) and
46- t .getAHandler ( ) .getType ( ) .refersTo ( theStopIterationType ( ) )
50+ t .getAHandler ( ) .getType ( ) .pointsTo ( ClassValue :: stopIteration ( ) )
4751 )
4852}
4953
5054from CallNode call
5155where call_to_next ( call , _) and
56+ not call_to_next_has_default ( call ) and
5257not exists ( EssaVariable iterator |
5358 call_to_next ( call , iterator .getAUse ( ) ) and
5459 iter_not_exhausted ( iterator )
@@ -58,4 +63,3 @@ not exists(Comp comp | comp.contains(call.getNode())) and
5863not stop_iteration_handled ( call )
5964
6065select call , "Call to next() in a generator"
61-
0 commit comments