Lichen

Annotated tests/methods_changing.py

934:2989aab1b4f7
10 months ago Paul Boddie Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality.
paul@267 1
class C:
paul@267 2
    def f(self):
paul@267 3
        return 1
paul@267 4
paul@267 5
    def g(self):
paul@267 6
        return self.f()
paul@267 7
paul@267 8
class D(C):
paul@267 9
    pass
paul@267 10
paul@267 11
def f():
paul@267 12
    return 2
paul@267 13
paul@267 14
c = C()
paul@267 15
d = D()
paul@267 16
paul@267 17
# Invoke a method that calls the default version of f.
paul@267 18
paul@267 19
print c.g()                 # 1
paul@267 20
print d.g()                 # 1
paul@267 21
paul@267 22
# Replace f in C and invoke the method again. For C, f will have changed,
paul@267 23
# but for D, f will retain its original value.
paul@267 24
paul@267 25
C.f = f
paul@267 26
paul@267 27
print c.g()                 # 2
paul@267 28
print d.g()                 # 1