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 
work.

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
True
>>> 1 < Decimal("2.0")
True
>>> 1 > Decimal("2.0")
False
>>> 1 > 2.0
False
>>> True > 0.5
True
>>> True > 1.5
False
>>> True > Decimal("0.5")
True
>>> True > Decimal("1.5")
False

Are you suggesting to change all the above comparisons to raise a TypeError?

cheers

Antoine.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to