1.1 --- a/tests/methods_unbound.py Fri Nov 25 19:20:37 2016 +0100
1.2 +++ b/tests/methods_unbound.py Fri Nov 25 21:20:41 2016 +0100
1.3 @@ -1,25 +1,50 @@
1.4 class C:
1.5 +
1.6 + "Class providing class and instance attributes."
1.7 +
1.8 def __init__(self):
1.9 self.a = 1
1.10 +
1.11 def m(self, x):
1.12 return x
1.13
1.14 class D:
1.15 +
1.16 + "An alternative class."
1.17 +
1.18 pass
1.19
1.20 def getc():
1.21 +
1.22 + "Return an instance of C to test object suitability."
1.23 +
1.24 return C()
1.25
1.26 def getd():
1.27 +
1.28 + "Return an instance of D to test object suitability."
1.29 +
1.30 return D()
1.31
1.32 def f(obj, i):
1.33 +
1.34 + """
1.35 + Obtain an attribute on 'obj', performing an operation depending on 'i'.
1.36 + This tests attribute access and invocation.
1.37 + """
1.38 +
1.39 if i:
1.40 return obj.m(i) # should cause access to an unbound method
1.41 else:
1.42 return obj.m
1.43
1.44 def g(obj, i):
1.45 +
1.46 + """
1.47 + Obtain an attribute on 'obj', performing an operation depending on 'i'.
1.48 + This tests attribute access and invocation, restricting 'obj' using a guard.
1.49 + """
1.50 +
1.51 obj.a # only provided by instances of C
1.52 if i:
1.53 return obj.m(i) # should use the method directly since obj is an instance
1.54 @@ -27,6 +52,13 @@
1.55 return obj.m
1.56
1.57 def h(obj, fn):
1.58 +
1.59 + """
1.60 + Obtain an attribute on 'obj', performing an operation depending on 'fn'.
1.61 + This tests attribute access and invocation, restricting 'obj' using a guard
1.62 + on a re-assignment of the name.
1.63 + """
1.64 +
1.65 if fn:
1.66 obj = fn()
1.67 obj.a # only provided by instances of C
1.68 @@ -34,6 +66,8 @@
1.69 else:
1.70 return obj.m
1.71
1.72 +# Main program.
1.73 +
1.74 c = C()
1.75
1.76 try: