
On Mon, Jun 25, 2018 at 02:35:28PM -0400, Cole Robinson wrote:
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
Signed-off-by: Cole Robinson <crobinso@redhat.com> --- libvirtaio.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
If we don't care about python3 < 3.4.4 compat, we can just do
from asyncio import ensure_future
diff --git a/libvirtaio.py b/libvirtaio.py index 1c432dd..9d517e6 100644 --- a/libvirtaio.py +++ b/libvirtaio.py @@ -43,10 +43,12 @@ import warnings
import libvirt
-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'
This is slightly misleading, I would remove the ' < 3.7' part as we need 'ensure_future' even for that versions. The following explanation is good enough.
+# 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")
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>