[blivet] Convert input to arithmetic functions to Decimal.
David Shea
dshea at redhat.com
Wed Jan 15 20:26:59 UTC 2014
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.
---
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. """
--
1.8.4.2
More information about the anaconda-patches
mailing list