[Python-Dev] Decimal <-> float comparisons in py3k.

Guido van Rossum guido at python.org
Tue Mar 16 18:15:28 CET 2010


On Tue, Mar 16, 2010 at 9:07 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
> On Tue, Mar 16, 2010 at 4:41 PM, Guido van Rossum <guido at python.org> wrote:
>> I'd say if you're not going to forward-port this to Python 3, it
>> shouldn't go into Python 2 -- in that case it would make more sense to
>> me to back-port the exception-raising behavior.
>
> That's also a possible solution, and the one that I'd personally be
> happiest with.  The main problem is that this has the potential to
> break code:  lists containing both floats and Decimals are sortable in
> 2.6, but would no longer be sortable in 2.7.  If such breakage is
> deemed acceptable then I'd happily backport the exception;  I really
> don't have a good feeling for how much real-world code could break, if
> any.

Definitely some. Stricter comparison rules are a frequent cause of
problems when code is first ported to 3.x. While you'd think that code
comparing a float and a Decimal is *already* broken, there's a
surprising number of situations where that's not necessary the case,
e.g. when an arbitrary but stable ordering is needed.

>> Also supporting comparisons but not other mixed operations is going to
>> be confusing. If you are sticking to that behavior I think mixed
>> comparisons should also be ruled out.
>
> Confusing, yes, but at least not bug-prone.  The current 2.x behaviour
> has provoked complaints from a number of different people in various
> different fora (I recently saw this come up on StackOverflow), and
> after initially being skeptical I'm now convinced that it would be a
> good idea to change it if at all possible.

Yeah, it should have raised an exception all along. But it's too late
for that now. I wonder if it should just become a py3k warning?

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list