[Python-Dev] Decimal &amp; lt; -&amp; gt; float comparisons in py3k.
solipsis at pitrou.net
Fri Mar 19 19:11:18 CET 2010
Raymond Hettinger <raymond.hettinger <at> gmail.com> writes:
> The reason to prefer an exception is that decimal/float comparisons
> are more likely to be a programmer error than an intended behavior.
Not more so than float/int or decimal/int or bool/int comparisons, which all
We forbid comparisons when there is a real danger or ambiguity, such as unicode
vs. bytes. There is no such danger or ambiguity when comparing a decimal with a
float. I don't see the point of being so restrictive; Python is not Java, and
typing is not supposed to be a synonym for bondage.
> Of course there is a precedent, I can compare "120" < 140 in AWK
> and get an automatic implicit conversion
The proper precedent in this context, though, is this one (py3k):
>>> 1 < 2.0
>>> 1 < Decimal("2.0")
>>> 1 > Decimal("2.0")
>>> 1 > 2.0
>>> True > 0.5
>>> True > 1.5
>>> True > Decimal("0.5")
>>> True > Decimal("1.5")
Are you suggesting to change all the above comparisons to raise a TypeError?
More information about the Python-Dev