@@ -99,3 +99,39 @@ def dunder_dict_indirect_read():
9999 do_stuff (y ) # $ MISSING: tracked
100100
101101
102+ # ------------------------------------------------------------------------------
103+ # Tracking of attribute on class instance
104+ # ------------------------------------------------------------------------------
105+
106+ # attribute set in method
107+ # inspired by https://github.com/github/codeql/pull/6023
108+ class MyClass2 (object ):
109+ def __init__ (self ): # $ tracked=foo
110+ self .foo = tracked # $ tracked=foo tracked
111+
112+ def print_foo (self ): # $ MISSING: tracked=foo
113+ print (self .foo ) # $ MISSING: tracked=foo tracked
114+
115+ def possibly_uncalled_method (self ):
116+ print (self .foo ) # $ MISSING: tracked
117+
118+ instance = MyClass2 ()
119+ print (instance .foo ) # $ MISSING: tracked=foo tracked
120+ instance .print_foo () # $ MISSING: tracked=foo
121+
122+
123+ # attribute set from outside of class
124+ class MyClass3 (object ):
125+ def print_self (self ): # $ tracked=foo
126+ print (self ) # $ tracked=foo
127+
128+ def print_foo (self ): # $ tracked=foo
129+ print (self .foo ) # $ tracked=foo tracked
130+
131+ def possibly_uncalled_method (self ):
132+ print (self .foo ) # $ MISSING: tracked
133+
134+ instance = MyClass3 () # $ tracked=foo
135+ instance .print_self () # $ tracked=foo
136+ instance .foo = tracked # $ tracked=foo tracked
137+ instance .print_foo () # $ tracked=foo
0 commit comments