From e27528204c887b4099b892a0237766f187959737 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 25 Jun 2018 14:14:57 -0400 Subject: libvirtaio: Fix compat with python 3.7 In python 3.7, async is now a keyword, so this throws a syntax error: File "/usr/lib64/python3.7/site-packages/libvirtaio.py", line 49 from asyncio import async as ensure_future ^ SyntaxError: invalid syntax Switch to getattr trickery to accomplish the same goal Reviewed-by: Pavel Hrdina Reviewed-by: Andrea Bolognani Signed-off-by: Cole Robinson --- libvirtaio.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'libvirtaio.py') diff --git a/libvirtaio.py b/libvirtaio.py index 1c432dd..328e6f2 100644 --- a/libvirtaio.py +++ b/libvirtaio.py @@ -43,10 +43,13 @@ import warnings import libvirt -try: - from asyncio import ensure_future -except ImportError: - from asyncio import async as ensure_future +# 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 +ensure_future = getattr(asyncio, "ensure_future", None) +if not ensure_future: + ensure_future = getattr(asyncio, "async") class Callback(object): -- cgit v1.2.1