2013-10-31 | Paul Boddie | file changeset files shortlog | Added remarks about local namespaces and name usage observations. | 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 |