2016-11-26 | Paul Boddie | file changeset files shortlog | Changed serialisation to handle classes separately, since <class>.__str__ and <class>.__repr__ are interpreted as type.__str__ and type.__repr__ respectively (being provided by the class of <class>), but these methods would always be unbound even if directly obtained from <class>. |
paul@90 | 1 | class C: |
paul@90 | 2 | def m(self, x): |
paul@90 | 3 | return x |
paul@90 | 4 | |
paul@90 | 5 | def f(obj, i): |
paul@90 | 6 | if i: |
paul@90 | 7 | return obj.m(i) |
paul@90 | 8 | else: |
paul@90 | 9 | return obj.m |
paul@90 | 10 | |
paul@90 | 11 | c = C() |
paul@202 | 12 | print f(c, 1) # 1 |
paul@202 | 13 | print f(c, 0)(2) # 2 |
paul@90 | 14 | fn = f(c, 0) |
paul@202 | 15 | print fn(2) # 2 |