特異メソッド

特異メソッドできるんだあ!すばらしい!2007/10/13日の自分の日記に追記しておいた。


しかし、実装を見てみるとnew.pyの中では

from types import MethodType as instancemethod

となっていて、types.pyの中では

class _C:
    def _m(self): pass
ClassType = type(_C)
UnboundMethodType = type(_C._m)         # Same as MethodType
_x = _C()
InstanceType = type(_x)
MethodType = type(_x._m)

となっている。何故かdocstringどこにも定義されていないのにdocstringを持っている。何でシグネチャ

>>> print new.instancemethod.__doc__
instancemethod(function, instance, class)

Create an instance method object.

となるのか分からない…。それにしてもtypeの威力はすごい!