summaryrefslogtreecommitdiff
path: root/libvirtaio.py
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2018-06-25 14:14:57 -0400
committerCole Robinson <crobinso@redhat.com>2018-06-27 10:07:39 -0400
commite27528204c887b4099b892a0237766f187959737 (patch)
treecaad064ab40d4bcf63bef5254eed4f0885c59ea7 /libvirtaio.py
parent6c136b8150e1487efdbb10bfd32a5d8a0f84df16 (diff)
downloadlibvirt-python-e27528204c887b4099b892a0237766f187959737.tar.gz
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 <phrdina@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'libvirtaio.py')
-rw-r--r--libvirtaio.py11
1 files changed, 7 insertions, 4 deletions
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):