is it a bug ?

Sylvain Ferriol sferriol at imag.fr
Mon Oct 23 06:04:33 EDT 2006


Peter Otten a écrit :
> 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
> 
i can not use it because:
class toto(float):
   def __init__(self,a=None):pass

t=toto(a=3)
TypeError: 'a' is an invalid keyword argument for this function
> Peter



More information about the Python-list mailing list