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 demonstrate that the usage associated with the global |
paul@549 | 5 | 'obj' cannot be reliably calculated since a function exists that rebinds the |
paul@549 | 6 | name. |
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 | def change_global(): |
paul@549 | 28 | global obj |
paul@549 | 29 | obj = E() # changes the global, potentially invalidating usage observations |
paul@549 | 30 | |
paul@549 | 31 | c = C() |
paul@549 | 32 | d = D() |
paul@549 | 33 | e = E() |
paul@549 | 34 | |
paul@549 | 35 | obj = c |
paul@549 | 36 | obj = d |
paul@549 | 37 | |
paul@549 | 38 | if obj.f(): |
paul@550 | 39 | obj.g() |
paul@549 | 40 | change_global() |
paul@550 | 41 | x = obj.f() |
paul@549 | 42 | else: |
paul@549 | 43 | x = 2 |
paul@549 | 44 | |
paul@550 | 45 | result_4 = x |
paul@549 | 46 | |
paul@549 | 47 | # vim: tabstop=4 expandtab shiftwidth=4 |