2010-02-07 | Paul Boddie | file changeset files shortlog | Made attribute deletion usage cause a warning during inspection, not an error, so that inspection of the test program may be performed. Added an optimisation test around guard generation for name assignments. Fixed attribute usage merging to permit the recording of isolated pockets of attribute usage that are not propagated further in a program unit. |
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 |