From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GBbxDgH3v2BJbgAAWB0awg (envelope-from ) for ; Tue, 08 Jun 2021 19:02:25 -0400 Received: by simark.ca (Postfix, from userid 112) id 2ED401F163; Tue, 8 Jun 2021 19:02:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 622751E01F for ; Tue, 8 Jun 2021 19:02:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E25CC3985803 for ; Tue, 8 Jun 2021 23:02:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E25CC3985803 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623193343; bh=wWKoy0kX0HSEMSCuTuYmpzrNYx6p8EZAkMJ6j2IoDtE=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=oxSVjI3XuDMvfQXwYaRTUdk+GJI7VkpMJn5jsFgFQm7ldmdTgFiUEVbgAq+bZRhGu 5queHR8nj5uR9uEm4KUjekxzhS5X3vjdDD60iG3SG3DnE+AJ+1m355KIFhTRHm8khy AqAHwH9fJ+wJh8jyaz366r6/s9pW6gjkBo9zvSL8= 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 To: Simon Marchi 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-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: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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.