2018-07-03 | Paul Boddie | file changeset files shortlog | Take advantage of context testing when acquiring functions for invocation. Since a context whose nature has been determined will have been tested, either as a consequence of deduction or at run-time, use of __get_function (which tests the context again) is unnecessary. |
paul@815 | 1 | f = lambda x: (x, 1) |
paul@815 | 2 | |
paul@815 | 3 | class C: |
paul@815 | 4 | f = lambda x: (x, 2) |
paul@815 | 5 | |
paul@815 | 6 | print f(123) # (123, 1) |
paul@815 | 7 | |
paul@815 | 8 | c = C() |
paul@815 | 9 | print c.f # __main__.C.$l0 |
paul@815 | 10 | print c.f(123) # (123, 2) |
paul@815 | 11 | |
paul@815 | 12 | c.f = f |
paul@815 | 13 | print c.f(123) # (123, 1) |
paul@815 | 14 | |
paul@815 | 15 | C.f = f |
paul@815 | 16 | c2 = C() |
paul@815 | 17 | print c2.f(123) # (123, 1) |