# HG changeset patch # User Paul Boddie # Date 1485208871 -3600 # Node ID 644952535f7ac171099b82aaf6671e4f8791ef71 # Parent 539b8b3433d3ad47dcc5de65ad5522712d516e9a Added another, shorter test of get_using, commenting the existing test slightly. diff -r 539b8b3433d3 -r 644952535f7a tests/get_using.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/get_using.py Mon Jan 23 23:01:11 2017 +0100 @@ -0,0 +1,19 @@ +class C: + def __init__(self): + self.x = 123 + + def f(self): + print self + return self.x + +c = C() +f = C.f +fn = get_using(C.f, c) +print fn # __main__.C.f +print fn() # 123 +fn = get_using(C.f, C) +print fn # __main__.C.f +try: + print fn() # fails +except UnboundMethodInvocation: + print "fn(): method is unbound" diff -r 539b8b3433d3 -r 644952535f7a tests/methods_unbound.py --- a/tests/methods_unbound.py Mon Jan 23 22:31:14 2017 +0100 +++ b/tests/methods_unbound.py Mon Jan 23 23:01:11 2017 +0100 @@ -83,6 +83,8 @@ except TypeError: print "f(d, 1): d is not a suitable argument." +# Get an unbound method, C.m. + fn = f(C, 0) try: @@ -91,6 +93,9 @@ print "fn(2): Unbound method is not callable." print get_using(fn, c)(2) # 2 + +# Repeat with fn re-evaluated. + print get_using(f(C, 0), c)(2) # 2 try: