[Python-Dev] Mixing float and Decimal -- thread reboot

Facundo Batista facundobatista at gmail.com
Sat Mar 20 00:17:24 CET 2010


On Fri, Mar 19, 2010 at 5:50 PM, Guido van Rossum <guido at python.org> wrote:

> As a downside, there is the worry that inadvertent mixing of Decimal
> and float can compromise the correctness of programs in a way that is
> hard to detect. But the anomalies above indicate that not fixing the

Decimal already has something that we can use in this case, and fits
very nice here: Signals.

Signals represent conditions that arise during computation. Each
corresponds to one context flag and one context trap enabler.

So, if we add a signal like "MixedWithFloats", users will have a flag
in the context that they could check to see if a float was mixed in
the operations executed (and if the user set the trap accordingly, an
exception will be raised when the signal happens).

OTOH, returning a float the first time both are mixed is easy to
check... but if it has downsides, and we prefer to return a Decimal in
that case, note that we have a mechanism in Decimal we can use.

Furthermore, in case we want to ease the transition we can do the following:

- add this signal

- set *by default* the trap to raise an exception when float and
Decimal is mixed

So, the behaviour will be the same as we have now, but users can
easily change it.

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


More information about the Python-Dev mailing list