1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/methods_changing.py Mon Nov 28 15:30:52 2016 +0100
1.3 @@ -0,0 +1,28 @@
1.4 +class C:
1.5 + def f(self):
1.6 + return 1
1.7 +
1.8 + def g(self):
1.9 + return self.f()
1.10 +
1.11 +class D(C):
1.12 + pass
1.13 +
1.14 +def f():
1.15 + return 2
1.16 +
1.17 +c = C()
1.18 +d = D()
1.19 +
1.20 +# Invoke a method that calls the default version of f.
1.21 +
1.22 +print c.g() # 1
1.23 +print d.g() # 1
1.24 +
1.25 +# Replace f in C and invoke the method again. For C, f will have changed,
1.26 +# but for D, f will retain its original value.
1.27 +
1.28 +C.f = f
1.29 +
1.30 +print c.g() # 2
1.31 +print d.g() # 1