From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SN87AWKa0GEdIwAAWB0awg (envelope-from ) for ; Sat, 01 Jan 2022 13:16:02 -0500 Received: by simark.ca (Postfix, from userid 112) id 02EEE1F0D9; Sat, 1 Jan 2022 13:16:02 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 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 938EB1F0D0 for ; Sat, 1 Jan 2022 13:16:01 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37DD43858000 for ; Sat, 1 Jan 2022 18:16:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37DD43858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1641060961; bh=NFB48iN1Z0XBWRHvsGjTn13qaepxajRZord3ryrJo3g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ZMZwbZdCCRJ7rYD5WlZ9qiTEBlDfCxy4pYxaemEJ5FusvADXXHtVdGKqDjpufE+tk TCNVm19OfZrestu/hwl4PDxzs21X6z2FL1vksugD/DS8qWwMx8Ls2rM47xtZ656Ptg qnGeehda7IIGdIdK3lUTgwt9MIsGbZfqIhkPQg0s= 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) 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-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: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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