micropython

Annotated tests/reference/methods.py

186:80ddd8db2612
2009-02-20 Paul Boddie Improved context-related documentation and related tests. Added a document about assignment and access.
paul@87 1
#!/usr/bin/env python
paul@87 2
paul@87 3
class A:
paul@87 4
    pass
paul@87 5
paul@87 6
class B:
paul@87 7
    def f(self):
paul@186 8
        print self
paul@87 9
paul@186 10
def f(self):
paul@186 11
    print self
paul@87 12
paul@87 13
b = B()
paul@87 14
paul@186 15
            # on A      on a        context on A attribute  context on a attribute
paul@186 16
A.f1 = f    # unbound   bound (a)   A                       a
paul@186 17
A.f2 = B.f  # unbound   unbound     B (need B instance)     B (need B instance)
paul@186 18
A.f3 = b.f  # bound (b) bound (b)   b                       b
paul@87 19
a = A()
paul@186 20
a.f4 = f    # N/A       function    N/A                     none
paul@186 21
a.f5 = B.f  # N/A       unbound     N/A                     B (need B instance)
paul@186 22
a.f6 = b.f  # N/A       bound (b)   N/A                     b
paul@87 23
paul@87 24
# vim: tabstop=4 expandtab shiftwidth=4