[PATCH 1/3] Do not pass context to Decimal numeric operations

Anne Mulhern amulhern at redhat.com
Wed Feb 18 16:44:53 UTC 2015


This will completely evaporate in new bytesize package, https://github.com/rhinstaller/bytesize.

But for now, I have no objections.

- mulhern

----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, February 18, 2015 11:15:14 AM
> Subject: [PATCH 1/3] Do not pass context to Decimal numeric operations
> 
> In Python 3 this causes an exception. We don't set it explicitly anywhere and
> the usage of Decimal we have in our code neither does it.
> 
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
>  blivet/size.py | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/blivet/size.py b/blivet/size.py
> index f493012..8be1870 100644
> --- a/blivet/size.py
> +++ b/blivet/size.py
> @@ -258,7 +258,7 @@ class Size(Decimal):
>  
>          # drop any partial byte
>          size = size.to_integral_value(rounding=ROUND_DOWN)
> -        self = Decimal.__new__(cls, value=size)
> +        self = Decimal.__new__(cls, value=size, context=context)
>          return self
>  
>      # Force str and unicode types since the translated sizespec may be
>      unicode
> @@ -278,26 +278,26 @@ class Size(Decimal):
>          return Size(self.convertTo())
>  
>      def __add__(self, other, context=None):
> -        return Size(Decimal.__add__(self, other, context=context))
> +        return Size(Decimal.__add__(self, other))
>  
>      # needed to make sum() work with Size arguments
>      def __radd__(self, other, context=None):
> -        return Size(Decimal.__radd__(self, other, context=context))
> +        return Size(Decimal.__radd__(self, other))
>  
>      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, other)
>  
>      def __mul__(self, other, context=None):
> -        return Size(Decimal.__mul__(self, other, context=context))
> +        return Size(Decimal.__mul__(self, other))
>      __rmul__ = __mul__
>  
>      def __div__(self, other, context=None):
> -        return Size(Decimal.__div__(self, other, context=context))
> +        return Size(Decimal.__div__(self, other))
>  
>      def __mod__(self, other, context=None):
> -        return Size(Decimal.__mod__(self, other, context=context))
> +        return Size(Decimal.__mod__(self, other))
>  
>      def convertTo(self, spec=None):
>          """ Return the size in the units indicated by the specifier.
> --
> 2.1.0
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 


More information about the anaconda-patches mailing list