私が辞書を持っているとしましょう:
>>> d = {}
メソッドがありますclear()
:
>>> d.clear
<built-in method clear of dict object at 0x7f209051c988>
...__hash__
属性があります:
>>> d.clear.__hash__
<method-wrapper '__hash__' of builtin_function_or_method object at 0x7f2090456288>
...呼び出し可能です:
>>> callable(d.clear.__hash__)
True
では、なぜハッシュ化できないのでしょうか。
>>> hash(d.clear)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
注:オブジェクトがハッシュ化できないことは知っていdict
ます。前述のように、オブジェクトはハッシュ化できないと主張しているように見えますが、なぜこの制限がオブジェクトのメソッドにも適用されるのか興味があります。