Lichen

Changeset

853:0687e5d1ed80
2018-07-12 Paul Boddie raw files shortlog changelog graph Demonstrate method and function assignments.
tests/methods_rebound.py (file)
     1.1 --- a/tests/methods_rebound.py	Thu Jul 12 16:46:25 2018 +0200
     1.2 +++ b/tests/methods_rebound.py	Thu Jul 12 17:14:37 2018 +0200
     1.3 @@ -13,9 +13,32 @@
     1.4  
     1.5  d = D()
     1.6  
     1.7 +def fn():
     1.8 +    return 456
     1.9 +
    1.10 +class E:
    1.11 +    f = fn
    1.12 +    g = C.f
    1.13 +
    1.14 +e = E()
    1.15 +
    1.16  print c.f.__name__                  # f
    1.17  print c.f()                         # <__main__.C instance>
    1.18                                      # 123
    1.19  print d.f.__name__                  # wrapper
    1.20  print d.f()                         # <__main__.C instance>
    1.21                                      # 123
    1.22 +
    1.23 +print e.f.__name__                  # fn
    1.24 +print e.f()                         # 456
    1.25 +print e.g.__name__                  # f
    1.26 +
    1.27 +try:
    1.28 +    print e.g()
    1.29 +except TypeError:
    1.30 +    print "e.g(): e is an incompatible instance for E.g which is C.f"
    1.31 +
    1.32 +g = get_using(E.g, c)
    1.33 +print g.__name__                    # f
    1.34 +print g()                           # <__main__.C instance>
    1.35 +                                    # 123