[PATCH] Consider Size as a numeric type if creating new instance

Anne Mulhern amulhern at redhat.com
Thu Jan 16 12:41:44 UTC 2014





----- Original Message -----
> From: "David Shea" <dshea at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, January 15, 2014 1:46:34 PM
> Subject: Re: [PATCH] Consider Size as a numeric type if creating new instance
> 
> On 01/15/2014 08:13 AM, Vratislav Podzimek wrote:
> > On Wed, 2014-01-15 at 07:54 -0500, Anne Mulhern wrote:
> >>
> >>
> >> ----- Original Message -----
> >>> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> >>> To: anaconda-patches at lists.fedorahosted.org
> >>> Sent: Wednesday, January 15, 2014 2:52:40 AM
> >>> Subject: [PATCH] Consider Size as a numeric type if creating new instance
> >>>
> >>> We can easily create a Decimal instance from it just as for int, float
> >>> and
> >>> the
> >>> others.
> >>>
> >>> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> >>> ---
> >>>   blivet/size.py | 2 +-
> >>>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/blivet/size.py b/blivet/size.py
> >>> index 0173ac6..50e644e 100644
> >>> --- a/blivet/size.py
> >>> +++ b/blivet/size.py
> >>> @@ -152,7 +152,7 @@ class Size(Decimal):
> >>>               raise SizeParamsError("only specify one parameter")
> >>>   
> >>>           if bytes is not None:
> >>> -            if type(bytes).__name__ in ["int", "long", "float",
> >>> 'Decimal']:
> >>> +            if type(bytes).__name__ in ["int", "long", "float",
> >>> "Decimal",
> >>> "Size"]:
> >>>                   value = Decimal(bytes)
> >>>               else:
> >>>                   raise ValueError("invalid value for bytes param")
> >>> --
> >>> 1.8.4.2
> >>>
> >>> _______________________________________________
> >>> anaconda-patches mailing list
> >>> anaconda-patches at lists.fedorahosted.org
> >>> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> >>>
> >> Maybe it would be better to use isinstance(bytes, <tuple>) than
> >> type(bytes).__name__ in <list> to achieve the same effect.
> > Maybe. There are at least 5 ways of fixing the issue and I really have
> > no idea which one should be preferred.
> >
> 
> I think I'd prefer isinstance, since that way we wouldn't need a special
> case for bytes=Size: Size is already a Decimal.
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

Yeah, that was my original motivation for suggesting it.

But it does make a difference, someone might inherit from int. ;)

- mulhern


More information about the anaconda-patches mailing list