File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
lib/semmle/python/frameworks
test/experimental/dataflow/fieldflow Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -3795,6 +3795,30 @@ private module StdlibPrivate {
3795
3795
preservesValue = true
3796
3796
}
3797
3797
}
3798
+
3799
+ /**
3800
+ * A flow summary for `dict.setdefault`.
3801
+ *
3802
+ * See https://docs.python.org/3.10/library/stdtypes.html#dict.setdefault
3803
+ */
3804
+ class DictSetdefaultSummary extends SummarizedCallable {
3805
+ DictSetdefaultSummary ( ) { this = "dict.setdefault" }
3806
+
3807
+ override DataFlow:: CallCfgNode getACall ( ) {
3808
+ result .( DataFlow:: MethodCallNode ) .calls ( _, "setdefault" )
3809
+ }
3810
+
3811
+ override DataFlow:: ArgumentNode getACallback ( ) {
3812
+ result .( DataFlow:: AttrRead ) .getAttributeName ( ) = "setdefault"
3813
+ }
3814
+
3815
+ override predicate propagatesFlowExt ( string input , string output , boolean preservesValue ) {
3816
+ // store/read steps with dictionary content of this is modeled in DataFlowPrivate
3817
+ input = "Argument[1]" and
3818
+ output = "ReturnValue" and
3819
+ preservesValue = true
3820
+ }
3821
+ }
3798
3822
}
3799
3823
3800
3824
// ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ def test_dict_update():
49
49
def test_setdefault ():
50
50
d = {}
51
51
x = d .setdefault ("key" , SOURCE )
52
- SINK (x ) # $ MISSING: flow="SOURCE, l:-1 -> d.setdefault(..) "
52
+ SINK (x ) # $ flow="SOURCE, l:-1 -> x "
53
53
SINK (d ["key" ]) # $ flow="SOURCE, l:-2 -> d['key']"
54
54
SINK (d .setdefault ("key" , NONSOURCE )) # $ flow="SOURCE, l:-3 -> d.setdefault(..)"
55
55
You can’t perform that action at this time.
0 commit comments