1 #!/usr/bin/env python 2 3 class C: 4 def f(self): 5 return 1 6 7 class D: 8 def f(self): 9 return 2 10 11 def g(self): 12 return 3 13 14 class E: 15 def f(self): 16 return 4 17 18 def h(self): 19 return 5 20 21 def test_conditional(obj): 22 # obj: C, D, E (f) 23 if obj.f(): # C, D, E (f) 24 obj.g() # D (f, g) 25 # else: 26 # ... # obj: C, D, E (f) 27 # # (f, g) ^ (f) 28 return 2 29 30 def test_new(obj, obj2): 31 # obj: C, D, E (f) 32 # obj2: 33 if obj.f(): # C, D, E (f) 34 obj = obj2 # obj: D (g) 35 obj.g() # D (g) 36 # else: 37 # ... # obj: C, D, E (f) 38 # # (g) ^ (f) 39 return obj.f() # C, D, E (f) 40 41 def test_neither(obj, obj2): 42 # obj: 43 # obj2: 44 if 0: 45 obj.g() # D (g) 46 else: 47 obj.f() # C, D, E (f) 48 # # (g) ^ (f) 49 return 4 50 51 def test_new_conditional(obj, obj2): 52 # obj: 53 # obj2: 54 if obj.f(): # C, D, E (f) 55 obj = obj2 # obj: D (g) 56 obj.g() # D (g) 57 else: 58 obj.h() # E (f, h) 59 # # (g) ^ (f, h) 60 return 5 61 62 c = C() 63 d = D() 64 e = E() 65 result1_2 = test_conditional(d) 66 result2_2 = test_new(c, d) 67 result1_4 = test_neither(c, d) 68 result1_5 = test_new_conditional(e, d) 69 70 # vim: tabstop=4 expandtab shiftwidth=4