1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/attribute_access_type_restriction_global_reassigned.py Tue Jun 19 00:29:57 2012 +0200
1.3 @@ -0,0 +1,46 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +This test attempts to demonstrate that the usage associated with the global
1.8 +'obj' cannot be reliably calculated since a function exists that rebinds the
1.9 +name.
1.10 +"""
1.11 +
1.12 +class C:
1.13 + def f(self): # unused but retained
1.14 + return 1
1.15 +
1.16 +class D:
1.17 + def f(self):
1.18 + return 2
1.19 +
1.20 + def g(self):
1.21 + return 3
1.22 +
1.23 +class E:
1.24 + def f(self): # unused but retained
1.25 + return 4
1.26 +
1.27 + def h(self): # unused
1.28 + return 5
1.29 +
1.30 +def change_global():
1.31 + global obj
1.32 + obj = E() # changes the global, potentially invalidating usage observations
1.33 +
1.34 +c = C()
1.35 +d = D()
1.36 +e = E()
1.37 +
1.38 +obj = c
1.39 +obj = d
1.40 +
1.41 +if obj.f():
1.42 + change_global()
1.43 + x = obj.g()
1.44 +else:
1.45 + x = 2
1.46 +
1.47 +result_3 = x
1.48 +
1.49 +# vim: tabstop=4 expandtab shiftwidth=4