[blivet] Convert input to arithmetic functions to Decimal.
David Lehman
dlehman at redhat.com
Wed Jan 15 20:45:09 UTC 2014
On Wed, 2014-01-15 at 15:26 -0500, David Shea wrote:
> Decimal can't work with a float unless it's explicitly converted to a
> Decimal first. This is a problem when using values returned by parted,
> which are float instead of Size.
I would rather fix all the places we try to do float math with Size
because we shouldn't be doing any. If we need a more explicit error,
fine. I just don't want to pretend it's okay to use float with Size
since it's not.
David
> ---
> blivet/size.py | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/blivet/size.py b/blivet/size.py
> index 0173ac6..e9735c5 100644
> --- a/blivet/size.py
> +++ b/blivet/size.py
> @@ -178,25 +178,25 @@ class Size(Decimal):
> return Size(bytes=self.convertTo(en_spec="b"))
>
> def __add__(self, other, context=None):
> - return Size(bytes=Decimal.__add__(self, other, context=context))
> + return Size(bytes=Decimal.__add__(self, Decimal(other), context=context))
>
> # needed to make sum() work with Size arguments
> def __radd__(self, other, context=None):
> - return Size(bytes=Decimal.__radd__(self, other, context=context))
> + return Size(bytes=Decimal.__radd__(self, Decimal(other), context=context))
>
> def __sub__(self, other, context=None):
> # subtraction is implemented using __add__ and negation, so we'll
> # be getting passed a Size
> - return Decimal.__sub__(self, other, context=context)
> + return Decimal.__sub__(self, Decimal(other), context=context)
>
> def __mul__(self, other, context=None):
> - return Size(bytes=Decimal.__mul__(self, other, context=context))
> + return Size(bytes=Decimal.__mul__(self, Decimal(other), context=context))
>
> def __div__(self, other, context=None):
> - return Size(bytes=Decimal.__div__(self, other, context=context))
> + return Size(bytes=Decimal.__div__(self, Decimal(other), context=context))
>
> def __mod__(self, other, context=None):
> - return Size(bytes=Decimal.__mod__(self, other, context=context))
> + return Size(bytes=Decimal.__mod__(self, Decimal(other), context=context))
>
> def _trimEnd(self, val):
> """ Internal method to trim trailing zeros. """
More information about the anaconda-patches
mailing list