Bug? ( () == [] ) != ( ().__eq__([]) )

MRAB python at mrabarnett.plus.com
Sun Aug 4 19:05:46 EDT 2013


On 04/08/2013 23:35, Markus Rother wrote:
> Hello,
>
> The following behaviour seen in 3.2 seems very strange to me:
>
> As expected:
>   >>> () == []
> False
>
> However:
>   >>> ().__eq__([])
> NotImplemented
>   >>> [].__eq__(())
> NotImplemented
>
> And:
>   >>> bool(NotImplemented)
> True
>
> Hence:
>   >>> bool(().__eq__([]))
> True
>   >>> ( () == [] ) != ( ().__eq__([]) )
> True
>
> How/why can this be intended?
>
The docs say:

"""NotImplemented
This type has a single value. There is a single object with this value. 
This object is accessed through the built-in name NotImplemented. 
Numeric methods and rich comparison methods may return this value if 
they do not implement the operation for the operands provided. (The 
interpreter will then try the reflected operation, or some other 
fallback, depending on the operator.) Its truth value is true.
"""




More information about the Python-list mailing list