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@297 | 1 | #!/usr/bin/env python |
paul@297 | 2 | |
paul@297 | 3 | """ |
paul@297 | 4 | This test attempts to guard 'obj' in 'test_one' with only an instance check for |
paul@297 | 5 | D instances. In the process, the unused methods should be discarded. |
paul@297 | 6 | """ |
paul@297 | 7 | |
paul@297 | 8 | class C: |
paul@297 | 9 | def f(self): # unused |
paul@297 | 10 | return 1 |
paul@297 | 11 | |
paul@297 | 12 | class D: |
paul@297 | 13 | def f(self): |
paul@297 | 14 | return 2 |
paul@297 | 15 | |
paul@297 | 16 | def __init__(self, g): |
paul@297 | 17 | self.g = g |
paul@297 | 18 | |
paul@297 | 19 | class E: |
paul@297 | 20 | def f(self): # unused |
paul@297 | 21 | return 4 |
paul@297 | 22 | |
paul@297 | 23 | def h(self): # unused |
paul@297 | 24 | return 5 |
paul@297 | 25 | |
paul@297 | 26 | def test_one(obj): |
paul@297 | 27 | # obj: D (f, g) |
paul@297 | 28 | obj.f() # C, D, E (f) |
paul@297 | 29 | return obj.g # D (f, g) - instance only |
paul@297 | 30 | |
paul@297 | 31 | c = C() |
paul@297 | 32 | d = D(4) |
paul@297 | 33 | e = E() |
paul@297 | 34 | result1_4 = test_one(d) |
paul@297 | 35 | |
paul@297 | 36 | # vim: tabstop=4 expandtab shiftwidth=4 |