From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (vps-42846194.vps.ovh.net [IPv6:2001:41d0:801:2000::2400]) by sourceware.org (Postfix) with ESMTPS id E83F93833036 for ; Tue, 8 Jun 2021 23:02:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E83F93833036 Received: from Plymouth (unknown [IPv6:2a02:390:9086:0:a53f:59dc:b325:2c3f]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 5BDCE81895; Tue, 8 Jun 2021 23:02:02 +0000 (UTC) Date: Wed, 9 Jun 2021 00:01:54 +0100 From: Lancelot SIX To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Use is/is not to check for None in python. Message-ID: <20210608230141.g6rgieanl7irigko@Plymouth> References: <20210607225044.486370-1-lsix@lancelotsix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Tue, 08 Jun 2021 23:02:02 +0000 (UTC) X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jun 2021 23:02:05 -0000 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.