[libvirt] [RFC PATCH v2 8/8] python3: Fix sort function

Daniel P. Berrangé berrange at redhat.com
Thu Mar 15 16:31:41 UTC 2018


On Thu, Mar 15, 2018 at 05:11:10PM +0100, Andrea Bolognani wrote:
> This deals with cls.version possibly being None.
> 
> Signed-off-by: Andrea Bolognani <abologna at redhat.com>
> ---
> Really not sure about this one. The script runs all the way to
> the end after applying it, so there's that I guess.

Python2 sorts  None before "", which is in turn before
any other non-zero length string. eg

   None < "" < "a"

I'm thinking that cls.version doesn't care about the
distinction between None and "", so your change is
likely to be fine.

> 
>  src/hyperv/hyperv_wmi_generator.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_generator.py
> index 7dc11ba905..d548102117 100755
> --- a/src/hyperv/hyperv_wmi_generator.py
> +++ b/src/hyperv/hyperv_wmi_generator.py
> @@ -59,7 +59,7 @@ class WmiClass:
>          """
>          # sort vesioned classes by version in case input file did not have them
>          # in order
> -        self.versions = sorted(self.versions, key=lambda cls: cls.version)
> +        self.versions = sorted(self.versions, key=lambda cls: cls.version or "")
>  
>          # if there's more than one verion make sure first one has name suffixed
>          # because we'll generate "common" memeber and will be the "base" name

Reviewed-by: Daniel P. Berrangé <berrange at redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list