From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id DLZ1IwI5V2OJShAAWB0awg (envelope-from ) for ; Mon, 24 Oct 2022 21:16:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 853FE1E112; Mon, 24 Oct 2022 21:16:50 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=JI0cXzgz; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.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 379521E0CB for ; Mon, 24 Oct 2022 21:16:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 286C438582B0 for ; Tue, 25 Oct 2022 01:16:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 286C438582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666660609; bh=EQthu0TV/O2vWNaLt1xRchAIJ0kgzHcjeavATTJMVJA=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JI0cXzgztyMGcosj91mnOCpioEDaiPiLONL+k9eMzhNobej2o48gLm5XN/YMVQYoY Ls7VTWKxs0I/Ynwzge2rTd6+pn2OLig7dzi4AB+W1bM9EePBS8NE48cNXEr8cLo0zv wxhc7r2oq5A584c+hffBXJU36TNPrMY9/IpKkCLw= Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 9A6A83858C2D for ; Tue, 25 Oct 2022 01:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9A6A83858C2D Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id DB1021E0CB; Mon, 24 Oct 2022 21:16:26 -0400 (EDT) Message-ID: Date: Mon, 24 Oct 2022 21:16:26 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH] gdb: copyright: make file header scan a bit more pythonic Content-Language: en-US To: Mike Frysinger , gdb-patches@sourceware.org References: <20220101181509.25740-1-vapier@gentoo.org> In-Reply-To: <20220101181509.25740-1-vapier@gentoo.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2022-01-01 13:15, Mike Frysinger via Gdb-patches wrote: > Should be functionally the same, but uses more pythonic idioms to get > fewer lines of code, and to make sure to not leak open file handles. > --- > gdb/copyright.py | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/gdb/copyright.py b/gdb/copyright.py > index a78f7f2aa9b0..918d2e473d49 100755 > --- a/gdb/copyright.py > +++ b/gdb/copyright.py > @@ -148,15 +148,12 @@ def may_have_copyright_notice(filename): > # so just open the file as a byte stream. We only need to search > # for a pattern that should be the same regardless of encoding, > # so that should be good enough. > - fd = open(filename, "rb") > - > - lineno = 1 > - for line in fd: > - if b"Copyright" in line: > - return True > - lineno += 1 > - if lineno > 50: > - return False > + with open(filename, "rb") as fd: > + for lineno, line in enumerate(fd, start=1): > + if b"Copyright" in line: > + return True > + if lineno > 50: I was checking the warnings given by flake8: copyright.py:143:5: F841 local variable 'MAX_LINES' is assigned to but never used I think this `50` was meant to be MAX_LINES. You might as well change the code to use it. LGTM in any case: Approved-By: Simon Marchi Simon