Lichen

tests/get_using.py

792:d70932955645
2017-03-31 Paul Boddie Fixed non-recognition of deferred references in non-module, non-function scopes.
     1 class C:     2     def __init__(self):     3         self.x = 123     4      5     def f(self):     6         return self.x     7      8 class D:     9     pass    10     11 c = C()    12 f = C.f    13 fn = get_using(C.f, c)    14 print fn                            # __main__.C.f    15 print fn()                          # 123    16     17 fn = get_using(C.f, C)    18 print fn                            # __main__.C.f    19 try:    20     print fn()                      # fails    21 except UnboundMethodInvocation:    22     print "fn(): method is unbound"    23     24 try:    25     print f()                       # fails    26 except UnboundMethodInvocation:    27     print "f(): method is unbound"    28     29 d = D()    30 try:    31     fn = get_using(C.f, d)    32 except TypeError:    33     print "get_using(C.f, d): d is not compatible with C"    34     35 fn = get_using(c, C.f)    36 print fn                            # <__main__.C instance>    37 try:    38     print fn()                      # fails    39 except TypeError:    40     print "fn(): object is not callable"