2013-06-29 | Paul Boddie | file changeset files shortlog | Separated handling of getattr attribute usage from normal program unit usage, tracking only newly introduced program constants when evaluating the effects of getattr usage, and thus limiting the amount of work done identifying new program units to investigate on each occasion. | syspython-as-target |
paul@549 | 1 | #!/usr/bin/env python |
paul@549 | 2 | |
paul@549 | 3 | """ |
paul@549 | 4 | This test attempts to record the usage of 'C', 'D' or 'E' in the module code |
paul@549 | 5 | since 'f' and 'g' might be used, but only 'f' is actually required. Although |
paul@549 | 6 | only 'D' provides both attributes, classes 'C' and 'E' provide 'f'. |
paul@549 | 7 | """ |
paul@549 | 8 | |
paul@549 | 9 | class C: |
paul@549 | 10 | def f(self): # unused but retained |
paul@549 | 11 | return 1 |
paul@549 | 12 | |
paul@549 | 13 | class D: |
paul@549 | 14 | def f(self): |
paul@549 | 15 | return 2 |
paul@549 | 16 | |
paul@549 | 17 | def g(self): |
paul@549 | 18 | return 3 |
paul@549 | 19 | |
paul@549 | 20 | class E: |
paul@549 | 21 | def f(self): # unused but retained |
paul@549 | 22 | return 4 |
paul@549 | 23 | |
paul@549 | 24 | def h(self): # unused |
paul@549 | 25 | return 5 |
paul@549 | 26 | |
paul@549 | 27 | c = C() |
paul@549 | 28 | d = D() |
paul@549 | 29 | e = E() |
paul@549 | 30 | |
paul@549 | 31 | obj = c |
paul@549 | 32 | obj = d |
paul@549 | 33 | # obj: f, g; f |
paul@549 | 34 | if obj.f(): |
paul@549 | 35 | x = obj.g() |
paul@549 | 36 | else: |
paul@549 | 37 | x = 2 |
paul@549 | 38 | |
paul@549 | 39 | result_3 = x |
paul@549 | 40 | |
paul@549 | 41 | # vim: tabstop=4 expandtab shiftwidth=4 |