1111 */
1212
1313import python
14+ import semmle.python.pointsto.PointsTo
1415
1516predicate rhs_in_expr ( ControlFlowNode rhs , Compare cmp ) {
1617 exists ( Cmpop op , int i | cmp .getOp ( i ) = op and cmp .getComparator ( i ) = rhs .getNode ( ) |
17- op instanceof In or op instanceof NotIn
18+ op instanceof In or op instanceof NotIn
1819 )
1920}
2021
21- from ControlFlowNode non_seq , Compare cmp , ClassObject cls , ControlFlowNode origin
22- where rhs_in_expr ( non_seq , cmp ) and
23- non_seq .refersTo ( _, cls , origin ) and
24- not cls .failedInference ( ) and
25- not cls .hasAttribute ( "__contains__" ) and
26- not cls .hasAttribute ( "__iter__" ) and
27- not cls .hasAttribute ( "__getitem__" ) and
28- not cls = theNoneType ( )
29-
30- select cmp , "This test may raise an Exception as the $@ may be of non-container class $@." , origin , "target" , cls , cls .getName ( )
22+ from ControlFlowNode non_seq , Compare cmp , Value v , ClassValue cls , ControlFlowNode origin
23+ where
24+ rhs_in_expr ( non_seq , cmp ) and
25+ non_seq .pointsTo ( _, v , origin ) and
26+ v .getClass ( ) = cls and
27+ not Types:: failedInference ( cls , _) and
28+ not cls .hasAttribute ( "__contains__" ) and
29+ not cls .hasAttribute ( "__iter__" ) and
30+ not cls .hasAttribute ( "__getitem__" ) and
31+ not cls = ClassValue:: nonetype ( ) and
32+ not cls = Value:: named ( "types.MappingProxyType" )
33+ select cmp , "This test may raise an Exception as the $@ may be of non-container class $@." , origin ,
34+ "target" , cls , cls .getName ( )
0 commit comments