# HG changeset patch # User Paul Boddie # Date 1531408477 -7200 # Node ID 0687e5d1ed801a4029e58d0b6b3deeb52fd044b0 # Parent 7c314a9d17241b43a3b15bb0e4e9690fa0eed0d8 Demonstrate method and function assignments. diff -r 7c314a9d1724 -r 0687e5d1ed80 tests/methods_rebound.py --- a/tests/methods_rebound.py Thu Jul 12 16:46:25 2018 +0200 +++ b/tests/methods_rebound.py Thu Jul 12 17:14:37 2018 +0200 @@ -13,9 +13,32 @@ d = D() +def fn(): + return 456 + +class E: + f = fn + g = C.f + +e = E() + print c.f.__name__ # f print c.f() # <__main__.C instance> # 123 print d.f.__name__ # wrapper print d.f() # <__main__.C instance> # 123 + +print e.f.__name__ # fn +print e.f() # 456 +print e.g.__name__ # f + +try: + print e.g() +except TypeError: + print "e.g(): e is an incompatible instance for E.g which is C.f" + +g = get_using(E.g, c) +print g.__name__ # f +print g() # <__main__.C instance> + # 123