From: Lancelot SIX <lsix@lancelotsix.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Use is/is not to check for None in python.
Date: Wed, 9 Jun 2021 00:01:54 +0100 [thread overview]
Message-ID: <20210608230141.g6rgieanl7irigko@Plymouth> (raw)
In-Reply-To: <d86eea98-19e8-d406-96b2-1ed614f89dc3@polymtl.ca>
On Tue, Jun 08, 2021 at 12:25:37PM -0400, Simon Marchi wrote:
> On 2021-06-07 9:12 p.m., Mike Frysinger via Gdb-patches wrote:
> > On 07 Jun 2021 23:50, Lancelot SIX via Gdb-patches wrote:
> >> While reviewing a patch sent to the mailing list, I noticed there are few
> >> places where python code checks if a variable is 'None' or not by using the
> >> comparison operators '==' and '!='. PEP8[1], which is used as coding standard
> >> in GDB coding standards, recommends using 'is' / 'is not' when comparing to a
> >> singleton such as 'None'.
> >
> > this is correct, so all the changes look fine. but i wonder if we couldn't
> > make many more pythonic by treating them as bools. for example:
>
> The patch LGTM but I also agree with Mike. So Lancelot, if you want to
> merge it as-is, that's fine. If you want to update it as suggested by
> Mike, that's fine too.
>
> Simon
>
Hi,
Thanks.
I have pushd the patch with minor modifications for the case Mike
pointed out.
After looking again, the pattern was:
fname = str(self.fobj.function())
if fname is None or fname == "":
return None
but in this situation fname can not be None. Worst case scenario, if
`self.fobj.function()` returns None, then `fname == 'None'`, so the
`is None` check is useless anyway.
For the rest, of the changes, I kept 'is None' / 'is not None'.
Lancelot.
prev parent reply other threads:[~2021-06-08 23:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-07 22:50 Lancelot SIX
2021-06-08 1:12 ` Mike Frysinger
2021-06-08 16:25 ` Simon Marchi
2021-06-08 23:01 ` Lancelot SIX [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=20210608230141.g6rgieanl7irigko@Plymouth \
--to=lsix@lancelotsix.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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 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 read-only IMAP folder(s) and NNTP newsgroup(s).