[issue4087] Document the effects of NotImplemented on == and !=

Raymond Hettinger report at bugs.python.org
Thu Oct 9 19:14:47 CEST 2008


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

Recommend not "doing anything" about decimals and other numbers.  What
you're seeing is a predictable consequence of NotImplemented being
returned by some but not all cross type comparisons.  IMO, it is
perfectly reasonable that both decimals and floats can be compared to
integers but not to each other.  Integers are a "universal donor" in
this respect but the two float types are not.

It is true that equality should be transitive but the same cannot be
said for the *ability of types* to be compared.  Unfortunately, the ==
operator masks what is going on by returning False instead of raising a
NotImplementedError.  IOW, it the apparant loss of transitivity when
"float(2) == Decimal(2)" returns False is an illusion; instead, the
False return means that the types cannot be compared at all.

If any doc changes are made with respect to this issue, it should be in
the docs for the == and != operators and for NotImplemented.

----------
assignee:  -> georg.brandl
components: +Documentation
nosy: +georg.brandl
priority: normal -> low
title: equality involving Decimals is not transitive;  strange set behaviour results -> Document the effects of NotImplemented on == and !=

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4087>
_______________________________________


More information about the Python-bugs-list mailing list