2011-05-10 | Paul Boddie | file changeset files shortlog | Added module identity information to the object table. This permits testing for module object types in guards. |
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@380 | 27 | # obj: f, g |
paul@380 | 28 | obj.f() |
paul@380 | 29 | return obj.g |
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 |