qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings


From: Markus Armbruster
Subject: Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
Date: Fri, 11 Oct 2019 08:01:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

Stefan Hajnoczi <address@hidden> 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é <address@hidden>
> Signed-off-by: Stefan Hajnoczi <address@hidden>
> ---
>  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):



reply via email to

[Prev in Thread] Current Thread [Next in Thread]