Lichen

tests/get_using.py

1027:dd0745ab8b8a
5 months ago Paul Boddie Reordered GCC arguments to prevent linking failures. Someone decided to change the GCC invocation or linking semantics at some point, meaning that libraries specified "too early" in the argument list no longer provide the symbols required by the program objects, whereas specifying them at the end of the argument list allows those symbols to be found and obtained.
     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"