# HG changeset patch # User Paul Boddie # Date 1480105241 -3600 # Node ID d6ac5b538330b0f91a9cac56b5b4c901022018b3 # Parent ed3fbc0d4e4a852843028fb64fbeeac776505a93 Added commentary and docstrings. diff -r ed3fbc0d4e4a -r d6ac5b538330 tests/methods_unbound.py --- a/tests/methods_unbound.py Fri Nov 25 19:20:37 2016 +0100 +++ b/tests/methods_unbound.py Fri Nov 25 21:20:41 2016 +0100 @@ -1,25 +1,50 @@ class C: + + "Class providing class and instance attributes." + def __init__(self): self.a = 1 + def m(self, x): return x class D: + + "An alternative class." + pass def getc(): + + "Return an instance of C to test object suitability." + return C() def getd(): + + "Return an instance of D to test object suitability." + return D() def f(obj, i): + + """ + Obtain an attribute on 'obj', performing an operation depending on 'i'. + This tests attribute access and invocation. + """ + if i: return obj.m(i) # should cause access to an unbound method else: return obj.m def g(obj, i): + + """ + Obtain an attribute on 'obj', performing an operation depending on 'i'. + This tests attribute access and invocation, restricting 'obj' using a guard. + """ + obj.a # only provided by instances of C if i: return obj.m(i) # should use the method directly since obj is an instance @@ -27,6 +52,13 @@ return obj.m def h(obj, fn): + + """ + Obtain an attribute on 'obj', performing an operation depending on 'fn'. + This tests attribute access and invocation, restricting 'obj' using a guard + on a re-assignment of the name. + """ + if fn: obj = fn() obj.a # only provided by instances of C @@ -34,6 +66,8 @@ else: return obj.m +# Main program. + c = C() try: