1import gc 2 3thingy = object() 4class A(object): 5 def f(self): 6 return 1 7 x = thingy 8 9r = gc.get_referrers(thingy) 10if "__module__" in r[0]: 11 dct = r[0] 12else: 13 dct = r[1] 14 15a = A() 16for i in range(10): 17 a.f() 18dct["f"] = lambda self: 2 19 20print(a.f()) # should print 1 21