why is self not passed to id()?
castironpi at gmail.com
Thu Sep 4 22:31:02 CEST 2008
On Sep 4, 3:26 pm, Ruediger <larud... at freenet.de> wrote:
> Executing following little program gives me an TypeError.
> What makes me wonder is that foo does get an argument passed while bar
> doesn't. Can anyone explain why??????
> class foo(list):
> __hash__ = lambda x: id(x)
> class bar(list):
> __hash__ = id
> _s_ = set()
> rue at linux:~> python test01.py
> Traceback (most recent call last):
> File "test01.py", line 9, in <module>
> TypeError: id() takes exactly one argument (0 given)
The answer is fairly technical. For member functions to be bound to
instances, they are required to have a __get__ method (which takes
instance and owner as parameters). 'id' does not.
(Why does 'id' not have a __get__ method?)
<method 'add' of 'set' objects>
['__call__', '__class__', '__delattr__', '__doc__', '__get__',
', '__hash__', '__init__', '__name__', '__new__', '__objclass__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__']
More information about the Python-list