2010-06-16 | Paul Boddie | file changeset files shortlog | Attempted to introduce a more conservative approach to visiting program units and collecting attributes. Moved the declaration of StopIteration into the inspection method for the "for" statement. Added module registration so that attribute collection successfully visits imported modules. |
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@310 | 22 | class E: |
paul@310 | 23 | def e(self): |
paul@310 | 24 | return 4 |
paul@310 | 25 | |
paul@310 | 26 | def f(self): |
paul@310 | 27 | return 0 # stops the test loop |
paul@310 | 28 | |
paul@310 | 29 | def g(self): |
paul@310 | 30 | return 5 |
paul@310 | 31 | |
paul@310 | 32 | def test_loop(obj, obj2): |
paul@310 | 33 | while obj.f(): |
paul@310 | 34 | obj.g() |
paul@310 | 35 | obj = obj2 # should support e, f, g |
paul@310 | 36 | obj.e() |
paul@310 | 37 | return obj.f() |
paul@310 | 38 | |
paul@310 | 39 | c = C() |
paul@310 | 40 | d = D() |
paul@310 | 41 | e = E() |
paul@310 | 42 | result1_0 = test_loop(d, e) |
paul@310 | 43 | |
paul@310 | 44 | # vim: tabstop=4 expandtab shiftwidth=4 |