All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Daniel P . Berrangé" <berrange@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
Date: Fri, 11 Oct 2019 08:01:58 +0200	[thread overview]
Message-ID: <87v9svlt0p.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20191010122154.10553-1-stefanha@redhat.com> (Stefan Hajnoczi's message of "Thu, 10 Oct 2019 13:21:54 +0100")

Stefan Hajnoczi <stefanha@redhat.com> writes:

> The following statement produces a SyntaxWarning with Python 3.8:
>
>   if len(format) is 0:
>   scripts/tracetool/__init__.py:459: SyntaxWarning: "is" with a literal. Did you mean "=="?
>
> Use the conventional len(x) == 0 syntax instead.
>
> Reported-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  scripts/tracetool/__init__.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
> index 04279fa62e..44c118bc2a 100644
> --- a/scripts/tracetool/__init__.py
> +++ b/scripts/tracetool/__init__.py
> @@ -456,12 +456,12 @@ def generate(events, group, format, backends,
>      import tracetool
>  
>      format = str(format)
> -    if len(format) is 0:
> +    if len(format) == 0:
>          raise TracetoolError("format not set")
>      if not tracetool.format.exists(format):
>          raise TracetoolError("unknown format: %s" % format)
>  
> -    if len(backends) is 0:
> +    if len(backends) == 0:
>          raise TracetoolError("no backends specified")
>      for backend in backends:
>          if not tracetool.backend.exists(backend):

For what it's worth, PEP 8 advises

    For sequences, (strings, lists, tuples), use the fact that empty
    sequences are false.

    Yes: if not seq:
         if seq:

    No:  if len(seq):
         if not len(seq):


      parent reply	other threads:[~2019-10-11  6:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 12:21 [PATCH] trace: avoid "is" with a literal Python 3.8 warnings Stefan Hajnoczi
2019-10-10 12:36 ` Daniel P. Berrangé
2019-10-10 14:02 ` Philippe Mathieu-Daudé
2019-10-10 16:13 ` Stefan Hajnoczi
2019-10-11  6:01 ` Markus Armbruster [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v9svlt0p.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.