From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1666660587; bh=Hcp9XLsSslDWTMMBrkt/P/t60BWIzjBxv88HXOSdyyI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=JLkywbVxbF2hglEKnygDkANe3Z9+7b/dmjRQxWB145jOYwp/geSa44udnPOLveodq Oq+LdS61loLCkA99Vegj70BdU9AmIpcDnIXIqhwp+7NMKjg6/goFkD6aDD8TqogJaf isaDnQNafn0cXJa8rWXwuovRFvlL+oPgHIKXbf5U= 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> From: Simon Marchi In-Reply-To: <20220101181509.25740-1-vapier@gentoo.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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