diff options
author | Cole Robinson <crobinso@redhat.com> | 2018-06-25 14:14:57 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2018-06-27 10:07:39 -0400 |
commit | e27528204c887b4099b892a0237766f187959737 (patch) | |
tree | caad064ab40d4bcf63bef5254eed4f0885c59ea7 /libvirtaio.py | |
parent | 6c136b8150e1487efdbb10bfd32a5d8a0f84df16 (diff) | |
download | libvirt-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.py | 11 |
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): |