* [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
@ 2019-10-10 12:21 Stefan Hajnoczi
2019-10-10 12:36 ` Daniel P. Berrangé
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2019-10-10 12:21 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel P . Berrangé, Stefan Hajnoczi
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):
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
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é
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel P. Berrangé @ 2019-10-10 12:36 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel
On Thu, Oct 10, 2019 at 01:21:54PM +0100, Stefan Hajnoczi wrote:
> 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(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
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
3 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-10-10 14:02 UTC (permalink / raw)
To: Stefan Hajnoczi, qemu-devel; +Cc: Daniel P . Berrangé
On 10/10/19 2:21 PM, Stefan Hajnoczi wrote:
> 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.
Ah this is a new change from 3.8...
https://docs.python.org/3.9/whatsnew/3.8.html
From https://bugs.python.org/issue34850
> Reported-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@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):
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
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
3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2019-10-10 16:13 UTC (permalink / raw)
To: qemu-devel; +Cc: Daniel P . Berrangé
[-- Attachment #1: Type: text/plain, Size: 634 bytes --]
On Thu, Oct 10, 2019 at 01:21:54PM +0100, Stefan Hajnoczi wrote:
> 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(-)
Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] trace: avoid "is" with a literal Python 3.8 warnings
2019-10-10 12:21 [PATCH] trace: avoid "is" with a literal Python 3.8 warnings Stefan Hajnoczi
` (2 preceding siblings ...)
2019-10-10 16:13 ` Stefan Hajnoczi
@ 2019-10-11 6:01 ` Markus Armbruster
3 siblings, 0 replies; 5+ messages in thread
From: Markus Armbruster @ 2019-10-11 6:01 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Daniel P . Berrangé, qemu-devel
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):
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-10-11 6:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).