1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/get_using.py Mon Jan 23 23:01:11 2017 +0100
1.3 @@ -0,0 +1,19 @@
1.4 +class C:
1.5 + def __init__(self):
1.6 + self.x = 123
1.7 +
1.8 + def f(self):
1.9 + print self
1.10 + return self.x
1.11 +
1.12 +c = C()
1.13 +f = C.f
1.14 +fn = get_using(C.f, c)
1.15 +print fn # __main__.C.f
1.16 +print fn() # 123
1.17 +fn = get_using(C.f, C)
1.18 +print fn # __main__.C.f
1.19 +try:
1.20 + print fn() # fails
1.21 +except UnboundMethodInvocation:
1.22 + print "fn(): method is unbound"
2.1 --- a/tests/methods_unbound.py Mon Jan 23 22:31:14 2017 +0100
2.2 +++ b/tests/methods_unbound.py Mon Jan 23 23:01:11 2017 +0100
2.3 @@ -83,6 +83,8 @@
2.4 except TypeError:
2.5 print "f(d, 1): d is not a suitable argument."
2.6
2.7 +# Get an unbound method, C.m.
2.8 +
2.9 fn = f(C, 0)
2.10
2.11 try:
2.12 @@ -91,6 +93,9 @@
2.13 print "fn(2): Unbound method is not callable."
2.14
2.15 print get_using(fn, c)(2) # 2
2.16 +
2.17 +# Repeat with fn re-evaluated.
2.18 +
2.19 print get_using(f(C, 0), c)(2) # 2
2.20
2.21 try: