1.1 --- a/tests/methods_unbound.py Fri Nov 25 18:36:45 2016 +0100
1.2 +++ b/tests/methods_unbound.py Fri Nov 25 19:20:37 2016 +0100
1.3 @@ -4,6 +4,15 @@
1.4 def m(self, x):
1.5 return x
1.6
1.7 +class D:
1.8 + pass
1.9 +
1.10 +def getc():
1.11 + return C()
1.12 +
1.13 +def getd():
1.14 + return D()
1.15 +
1.16 def f(obj, i):
1.17 if i:
1.18 return obj.m(i) # should cause access to an unbound method
1.19 @@ -17,6 +26,14 @@
1.20 else:
1.21 return obj.m
1.22
1.23 +def h(obj, fn):
1.24 + if fn:
1.25 + obj = fn()
1.26 + obj.a # only provided by instances of C
1.27 + return obj.m(1)
1.28 + else:
1.29 + return obj.m
1.30 +
1.31 c = C()
1.32
1.33 try:
1.34 @@ -41,3 +58,11 @@
1.35
1.36 print g(c, 1) # 1
1.37 print g(c, 0)(3) # 3
1.38 +
1.39 +print h(c, getc) # 1
1.40 +print h(c, 0)(4) # 4
1.41 +
1.42 +try:
1.43 + print h(c, getd) # should fail with an error caused by a guard
1.44 +except TypeError:
1.45 + print "h(c, getd): getd provides an unsuitable result."