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 {
97
97
*/
98
98
class Mutation extends Sink {
99
99
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
100
107
exists ( AugAssign a | a .getTarget ( ) .getAFlowNode ( ) = this .asCfgNode ( ) )
101
108
or
109
+ // modifying function call
102
110
exists ( DataFlow:: CallCfgNode c , DataFlow:: AttrRead a | c .getFunction ( ) = a |
103
111
a .getObject ( ) = this and
104
112
a .getAttributeName ( ) in [ list_modifying_method ( ) , dict_modifying_method ( ) ]
Original file line number Diff line number Diff line change 1
1
# Not OK
2
2
def simple (l = [0 ]):
3
- l [0 ] = 1 #$ MISSING: modification=l
3
+ l [0 ] = 1 #$ modification=l
4
4
return l
5
5
6
6
# Not OK
7
7
def slice (l = [0 ]):
8
- l [0 :1 ] = 1 #$ MISSING: modification=l
8
+ l [0 :1 ] = 1 #$ modification=l
9
9
return l
10
10
11
11
# Not OK
12
12
def list_del (l = [0 ]):
13
- del l [0 ] #$ MISSING: modification=l
13
+ del l [0 ] #$ modification=l
14
14
return l
15
15
16
16
# Not OK
@@ -51,21 +51,21 @@ def nonempty(l = [5]):
51
51
52
52
# Not OK
53
53
def dict (d = {}):
54
- d ['a' ] = 1 #$ MISSING: modification=d
54
+ d ['a' ] = 1 #$ modification=d
55
55
return d
56
56
57
57
# Not OK
58
58
def dict_nonempty (d = {'a' : 1 }):
59
- d ['a' ] = 2 #$ MISSING: modification=d
59
+ d ['a' ] = 2 #$ modification=d
60
60
return d
61
61
62
62
# OK
63
63
def dict_nonempty_nochange (d = {'a' : 1 }):
64
- d ['a' ] = 1
64
+ d ['a' ] = 1 #$ SPURIOUS: modification=d
65
65
return d
66
66
67
67
def modifies (d ):
68
- d ['a' ] = 1 #$ MISSING: modification=d
68
+ d ['a' ] = 1 #$ modification=d
69
69
return d
70
70
71
71
# Not OK
@@ -106,7 +106,7 @@ def dict_includes(d = {}):
106
106
107
107
# Not OK
108
108
def dict_del (d = {'a' : 1 }):
109
- del d ['a' ] #$ MISSING: modification=d
109
+ del d ['a' ] #$ modification=d
110
110
return d
111
111
112
112
# Not OK
You can’t perform that action at this time.
0 commit comments