[Python-Dev] Decimal <-> float comparisons in py3k. (original) (raw)

Mark Dickinson dickinsm at gmail.com
Thu Mar 18 19:41:08 CET 2010


On Thu, Mar 18, 2010 at 5:55 PM, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:

My thought is that intentional mixed compares of float and decimal are very rare relative to unintentional cases.  IOW, most of the time that x<y makes a float/decimal comparison, it is actually an error (or the user simply doesn't understand what his or her code is actually doing).  That user is best served by refusing the temptation to guess that they really wanted to go down this path.

In this case, could we consider again the idea of making these comparisons produce TypeErrors in 2.7? That's what's been requested or proposed multiple times on the tracker issue (by Imri Goldberg[1], Jeremy Dunck[2], Bert Hughes[3] and Stefan Krah[4]), and also by participants in this discussion (Greg Ewing).

I'm only seeing two arguments against this at the moment: (1) it has the potential to break code that relies on being able to sort heterogeneous lists. But given that heterogeneous lists can't be sorted stably anyway (see my earlier post about lists containing ints, floats and Decimals), perhaps this is an acceptable risk. (2) A few of the posters here (Steven, Nick, and me) feel that it's slightly more natural to allow these comparisons; but I think the argument's fairly evenly balanced at the moment between those who'd prefer an exception and those who'd prefer to allow the comparisons.

I'd really like to get this sorted for 2.7: as far as I'm concerned, either of the proposed behaviours (raise an exception, or allow comparisons) would be an improvement on the current 2.7 behaviour.

Could everyone live with making float<->Decimal comparisons raise an exception in 2.7?

Mark

[1] http://bugs.python.org/issue2531#msg83691 [2] http://bugs.python.org/issue2531#msg83818 [3] http://bugs.python.org/issue2531#msg97891 [4] http://bugs.python.org/issue2531#msg98217



More information about the Python-Dev mailing list