From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 5BB97385800D for ; Sat, 1 Jan 2022 18:15:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5BB97385800D Received: by smtp.gentoo.org (Postfix, from userid 559) id D0D65342C20; Sat, 1 Jan 2022 18:15:11 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH] gdb: copyright: make file header scan a bit more pythonic Date: Sat, 1 Jan 2022 13:15:09 -0500 Message-Id: <20220101181509.25740-1-vapier@gentoo.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Sat, 01 Jan 2022 18:15:13 -0000 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: + break return False -- 2.33.0