Re: [PATCH python] libvirtaio: Fix compat with python 3.7

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2018-06-25 at 14:35 -0400, Cole Robinson wrote:
[...]
> -try:
> -    from asyncio import ensure_future
> -except ImportError:
> -    from asyncio import async as ensure_future
> +# python < 3.4.4: we want 'async'
> +# python >= 3.4.4 < 3.7, we want 'ensure_future'
> +# python >= 3.7, 'async' is a reserved keyword, so we can't import it
> +ensure_future = getattr(asyncio, "ensure_future", None)
> +if not ensure_future:
> +    ensure_future = getattr(asyncio, "async")

Python is not exactly my forte, but the above makes sense to me
and it stood up to some testing across all platforms supported by
libvirt, so

  Reviewed-by: Andrea Bolognani <abologna@xxxxxxxxxx>

One nit is that the comment above the code doesn't IMHO describe
the situation properly: I would have worded it along the lines of

  # Python < 3.4.4 doesn't have 'ensure_future', so we have to fall
  # back to 'async'; however, since 'async' is a reserved keyword
  # in Python >= 3.7, we can't perform a straightforward import and
  # we have to resort to getattr() instead

I leave it up to you whether or not you want to reword the comment.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux