File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
python/ql/test/experimental/dataflow/typetracking Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -69,3 +69,35 @@ def redefine_test():
6969 expects_int (x ) # $int
7070 x = str ("Hello" ) # $str
7171 expects_string (x ) # $str
72+
73+ # ------------------------------------------------------------------------------
74+ # Tracking of self in methods
75+ # ------------------------------------------------------------------------------
76+
77+ class Foo (object ):
78+
79+ def meth1 (self ):
80+ do_stuff (self )
81+
82+ def meth2 (self ): # $ MISSING: tracked_self
83+ do_stuff (self ) # $ MISSING: tracked_self
84+
85+ def meth3 (self ): # $ MISSING: tracked_self
86+ do_stuff (self ) # $ MISSING: tracked_self
87+
88+
89+ class Bar (Foo ):
90+
91+ def meth1 (self ): # $ tracked_self
92+ do_stuff (self ) # $ tracked_self
93+
94+ def meth2 (self ):
95+ do_stuff (self )
96+
97+ def meth3 (self ):
98+ do_stuff (self )
99+
100+ def track_self (self ): # $ tracked_self
101+ self .meth1 () # $ tracked_self
102+ super ().meth2 ()
103+ super (Bar , self ).foo3 () # $ tracked_self
Original file line number Diff line number Diff line change @@ -73,3 +73,32 @@ class TrackedStringTest extends InlineExpectationsTest {
7373 )
7474 }
7575}
76+
77+ DataFlow:: Node tracked_self ( TypeTracker t ) {
78+ t .start ( ) and
79+ exists ( Function f |
80+ f .isMethod ( ) and
81+ f .getName ( ) = "track_self" and
82+ result .( DataFlow:: ParameterNode ) .getParameter ( ) = f .getArg ( 0 )
83+ )
84+ or
85+ exists ( TypeTracker t2 | result = tracked_self ( t2 ) .track ( t2 , t ) )
86+ }
87+
88+ class TrackedSelfTest extends InlineExpectationsTest {
89+ TrackedSelfTest ( ) { this = "TrackedSelfTest" }
90+
91+ override string getARelevantTag ( ) { result = "tracked_self" }
92+
93+ override predicate hasActualResult ( Location location , string element , string tag , string value ) {
94+ exists ( DataFlow:: Node e , TypeTracker t |
95+ e = tracked_self ( t ) and
96+ // Module variables have no sensible location, and hence can't be annotated.
97+ not e instanceof DataFlow:: ModuleVariableNode and
98+ tag = "tracked_self" and
99+ location = e .getLocation ( ) and
100+ value = t .getAttr ( ) and
101+ element = e .toString ( )
102+ )
103+ }
104+ }
You can’t perform that action at this time.
0 commit comments