is it a bug ?

Peter Otten __peter__ at web.de
Mon Oct 23 11:12:34 CEST 2006


Sylvain Ferriol wrote:

> can you explain to me what happened:
> 
> class toto(object):
>    eq = float.__eq__
> 
> t = toto()
> 
> getattr(t,'eq')
> TypeError: descriptor '__eq__' for 'float' objects doesn't apply to
> 'toto' object

float.__eq__ is probably implemented in C and its operation will make sense
only for instances of float or subclasses of float. Try

>>> class Toto(float):
...     eq = float.__eq__
...
>>> Toto().eq(42)
False

Peter



More information about the Python-list mailing list