2011-02-26 | Paul Boddie | file changeset files shortlog | Added tag feature-universal-__class__-attributes for changeset 83dc777c7083 |
paul@310 | 1 | #!/usr/bin/env python |
paul@310 | 2 | |
paul@310 | 3 | """ |
paul@310 | 4 | This test illustrates the need for usage to be propagated forward to the |
paul@310 | 5 | assignment within the loop. |
paul@310 | 6 | """ |
paul@310 | 7 | |
paul@310 | 8 | class C: |
paul@310 | 9 | def e(self): # unused |
paul@310 | 10 | return 1 |
paul@310 | 11 | |
paul@310 | 12 | def f(self): |
paul@310 | 13 | return 1 |
paul@310 | 14 | |
paul@310 | 15 | class D: |
paul@310 | 16 | def f(self): |
paul@310 | 17 | return 2 |
paul@310 | 18 | |
paul@310 | 19 | def g(self): |
paul@310 | 20 | return 3 |
paul@310 | 21 | |
paul@381 | 22 | def h(self): |
paul@381 | 23 | return 4 |
paul@381 | 24 | |
paul@310 | 25 | class E: |
paul@310 | 26 | def e(self): |
paul@310 | 27 | return 4 |
paul@310 | 28 | |
paul@310 | 29 | def f(self): |
paul@310 | 30 | return 0 # stops the test loop |
paul@310 | 31 | |
paul@310 | 32 | def g(self): |
paul@310 | 33 | return 5 |
paul@310 | 34 | |
paul@379 | 35 | def h(self): |
paul@379 | 36 | return 6 |
paul@379 | 37 | |
paul@310 | 38 | def test_loop(obj, obj2): |
paul@379 | 39 | # obj: f, g (from loop); f, h (outside loop) |
paul@310 | 40 | while obj.f(): |
paul@379 | 41 | # obj: g (in loop) |
paul@310 | 42 | obj.g() |
paul@379 | 43 | obj = obj2 # obj: e, f, h |
paul@310 | 44 | obj.e() |
paul@379 | 45 | # (test invoked again) |
paul@379 | 46 | return obj.h() |
paul@310 | 47 | |
paul@310 | 48 | c = C() |
paul@310 | 49 | d = D() |
paul@310 | 50 | e = E() |
paul@379 | 51 | result_6 = test_loop(d, e) |
paul@310 | 52 | |
paul@310 | 53 | # vim: tabstop=4 expandtab shiftwidth=4 |