From patchwork Mon Jun 25 18:35:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 139877 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4313231lji; Mon, 25 Jun 2018 11:36:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIJsQvNkZXhuU4H1oyiiw3VJSQIFFf8i5U57kGOLR3znMnEia5SKh6qyKmnCC4NiE2ThcLY X-Received: by 2002:a9d:1553:: with SMTP id z19-v6mr7525202otz.135.1529951807904; Mon, 25 Jun 2018 11:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529951807; cv=none; d=google.com; s=arc-20160816; b=TcqBVL4cR8dMwtjjEoUHPmD/+OCyH9C9a7O1ih2bGVBzVx/YuTFYtRnr836Q28WvZS cies89nMGSHGGTxCvXeL0UIlTyDEPwVpbCa8T9brCOxHMJnXLNDD9Gws47P617OONwlt vc5nFac+4dTZS6FxfBFfWSvcrXn5S6+Ys3PihobKM/1GvHu4IyOdGwH1WyiwqEHS1pxz T/6gcM+eDet1T44GgD1MZJEuo8B46YrPovPJBtEp2jTnx7lKVSepdmHx6k6iwr5tCIE+ KSPV/whDqCEVgPwWxsk1RVFDFRnTTY9mBDUr8+fUMxEHh63n/VZNPUI7YpbxmVF7jkgJ AmVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=GmiOHjgU1a6LJaPD7MvCGwKqD+rCiBrYZ9fUhtrldNc=; b=TQyqYQl9Y5YOCMRtBqj4BdKTd7gSh8yQ5arSg2+GQMy40+c8NlZyLyfzukiAhyPQ1q 1cID4n57afILun/dZWBN3uZXSiL2QqQFlbKYN3S7rNpJoUeeShC8YsmQWopMGhtrsPwd VsC7Y8OIyvh+pjQ2gCcWYLezMfNyfacvP87e167FqrHCQUqZyB+tC4jdGxtXiElp0Ar4 NhR1hvS87PfVTnXylP2NeRExSyTknM/OW8pgtvzyrj+CuAYxIeQMTNqcW5cdwNfTIg/v fUZpIDb2Jt15ssWTJs/kPEHhHWC7wDREQqmrtljxQXpi2nGYDw8drfkXO+as/Ku8ilQR Kt1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 126-v6si4825667oif.315.2018.06.25.11.36.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 11:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BB584E90C; Mon, 25 Jun 2018 18:36:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC9BD77E83; Mon, 25 Jun 2018 18:36:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EAB673FCC0; Mon, 25 Jun 2018 18:36:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5PIZXxZ008900 for ; Mon, 25 Jun 2018 14:35:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5436C59870; Mon, 25 Jun 2018 18:35:33 +0000 (UTC) Delivered-To: libvir-list@redhat.com Received: from worklaptop.redhat.com (ovpn-117-39.phx2.redhat.com [10.3.117.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBD74171D9; Mon, 25 Jun 2018 18:35:30 +0000 (UTC) From: Cole Robinson To: libvir-list@redhat.com Date: Mon, 25 Jun 2018 14:35:28 -0400 Message-Id: <1628bcfd04594298769425871cc1d5b515aefea1.1529950820.git.crobinso@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH python] libvirtaio: Fix compat with python 3.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 25 Jun 2018 18:36:46 +0000 (UTC) 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 --- 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 -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: Pavel Hrdina 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' +# 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") class Callback(object):