File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
src/semmle/python/functions
test/query-tests/Functions/ModificationOfParameterWithDefault Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -97,8 +97,16 @@ module ModificationOfParameterWithDefault {
9797 */
9898 class Mutation extends Sink {
9999 Mutation ( ) {
100+ // assignment to a subscript (includes slices)
101+ exists ( DefinitionNode d | d .( SubscriptNode ) .getObject ( ) = this .asCfgNode ( ) )
102+ or
103+ // deletion of a subscript
104+ exists ( DeletionNode d | d .getTarget ( ) .( SubscriptNode ) .getObject ( ) = this .asCfgNode ( ) )
105+ or
106+ // augmented assignment to the value
100107 exists ( AugAssign a | a .getTarget ( ) .getAFlowNode ( ) = this .asCfgNode ( ) )
101108 or
109+ // modifying function call
102110 exists ( DataFlow:: CallCfgNode c , DataFlow:: AttrRead a | c .getFunction ( ) = a |
103111 a .getObject ( ) = this and
104112 a .getAttributeName ( ) in [ list_modifying_method ( ) , dict_modifying_method ( ) ]
Original file line number Diff line number Diff line change 11# Not OK
22def simple (l = [0 ]):
3- l [0 ] = 1 #$ MISSING: modification=l
3+ l [0 ] = 1 #$ modification=l
44 return l
55
66# Not OK
77def slice (l = [0 ]):
8- l [0 :1 ] = 1 #$ MISSING: modification=l
8+ l [0 :1 ] = 1 #$ modification=l
99 return l
1010
1111# Not OK
1212def list_del (l = [0 ]):
13- del l [0 ] #$ MISSING: modification=l
13+ del l [0 ] #$ modification=l
1414 return l
1515
1616# Not OK
@@ -51,21 +51,21 @@ def nonempty(l = [5]):
5151
5252# Not OK
5353def dict (d = {}):
54- d ['a' ] = 1 #$ MISSING: modification=d
54+ d ['a' ] = 1 #$ modification=d
5555 return d
5656
5757# Not OK
5858def dict_nonempty (d = {'a' : 1 }):
59- d ['a' ] = 2 #$ MISSING: modification=d
59+ d ['a' ] = 2 #$ modification=d
6060 return d
6161
6262# OK
6363def dict_nonempty_nochange (d = {'a' : 1 }):
64- d ['a' ] = 1
64+ d ['a' ] = 1 #$ SPURIOUS: modification=d
6565 return d
6666
6767def modifies (d ):
68- d ['a' ] = 1 #$ MISSING: modification=d
68+ d ['a' ] = 1 #$ modification=d
6969 return d
7070
7171# Not OK
@@ -106,7 +106,7 @@ def dict_includes(d = {}):
106106
107107# Not OK
108108def dict_del (d = {'a' : 1 }):
109- del d ['a' ] #$ MISSING: modification=d
109+ del d ['a' ] #$ modification=d
110110 return d
111111
112112# Not OK
You can’t perform that action at this time.
0 commit comments