1313import python
1414import semmle.python.strings
1515
16- /* modernized query
1716from Expr e , ClassValue t
1817where exists ( BinaryExpr b | b .getOp ( ) instanceof Mod and format_string ( b .getLeft ( ) ) and e = b .getRight ( ) and
19- mapping_format(b.getLeft()) and e.pointsTo(_, t, _) and not t.isMapping())
20- select e, "Right hand side of a % operator must be a mapping, not class $@.", t, t.getName()
21- //*/
22-
23- /* original query
24- from Expr e, ClassObject t
25- where exists(BinaryExpr b | b.getOp() instanceof Mod and format_string(b.getLeft()) and e = b.getRight() and
26- mapping_format(b.getLeft()) and e.refersTo(_, t, _) and not t.isMapping())
27- select e, "Right hand side of a % operator must be a mapping, not class $@.", t, t.getName()
28- //*/
29-
30- //* debug query
31- from Expr e , ClassValue t , string s
32- where any ( )
33- and exists ( BinaryExpr b | any ( )
34- and b .getOp ( ) instanceof Mod
35- and format_string ( b .getLeft ( ) )
36- and e = b .getRight ( )
37- and mapping_format ( b .getLeft ( ) )
38- and e .pointsTo ( ) .getClass ( ) = t
39- //and not t.isMapping()
40- )
41- and if t .hasAttribute ( "__getitem__" ) then s = "yes" else s = "no"
42- select
43- e
44- , "Right hand side of a % operator must be a mapping, not class $@."
45- , t
46- , t .getName ( )
47- , s
48- , s
49- //*/
18+ mapping_format ( b .getLeft ( ) ) and e .pointsTo ( ) .getClass ( ) = t and not t .isMapping ( ) )
19+ select e , "Right hand side of a % operator must be a mapping, not class $@." , t , t .getName ( )
0 commit comments