From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UBNdJh+mVWPw1A8AWB0awg (envelope-from ) for ; Sun, 23 Oct 2022 16:37:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 9AF8A1E112; Sun, 23 Oct 2022 16:37:51 -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=EAiVCooU; 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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 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 4C2A31E0D5 for ; Sun, 23 Oct 2022 16:37:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76D7C385702C for ; Sun, 23 Oct 2022 20:37:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76D7C385702C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666557470; bh=kzr8W1rISTM/9dGgopWzyNfqmC+VKho6eAan8H/giSY=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EAiVCooUAs3FTA6zjr0U2eGlS9Ry/2yXzlfaNiGK2r3lkHb4tDyekt4j7uE2An3MA hjq8o1WGETMzQ3kRs/tquUeG1b7cyzIGbLZZ8fNaVJION69BzZ5NEXi8AXlWPFsRt2 Z5JUYfcT3Pezrf1vwO/z241Iur/T2RVI3mywFaDA= Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 21B54385AC20 for ; Sun, 23 Oct 2022 20:36:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21B54385AC20 Received: by smtp.gentoo.org (Postfix, from userid 559) id C81E0340952; Sun, 23 Oct 2022 20:36:42 +0000 (UTC) Date: Mon, 24 Oct 2022 01:07:17 +0545 To: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb: copyright: make file header scan a bit more pythonic Message-ID: Mail-Followup-To: gdb-patches@sourceware.org References: <20220101181509.25740-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6RJbXby++1bAxkKQ" Content-Disposition: inline In-Reply-To: <20220101181509.25740-1-vapier@gentoo.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: , From: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" --6RJbXby++1bAxkKQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable ping ... -mike On 01 Jan 2022 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(-) >=20 > 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 =3D open(filename, "rb") > - > - lineno =3D 1 > - for line in fd: > - if b"Copyright" in line: > - return True > - lineno +=3D 1 > - if lineno > 50: > - return False > + with open(filename, "rb") as fd: > + for lineno, line in enumerate(fd, start=3D1): > + if b"Copyright" in line: > + return True > + if lineno > 50: > + break > return False > =20 > =20 > --=20 > 2.33.0 >=20 --6RJbXby++1bAxkKQ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmNVlGkACgkQQWM7n+g3 9YHwMBAA138FJefCgm2LNSpHgFR0+F3NkUcdx/dfMiv3rPKdy8Rlm+/sN8MPsmNI ZXSE3ahlyU2I3Cz0ZYu32ik9eHSmAECRM1kJEitr+k/LI0X4bdJTl3YSSzQfB7+T w81ShfAOU6cLvMUXGnfxdHUEsipCu0xPltWApbqCxY4uU2fYexGrMp3+6C7WPGOf 1dn5TCkdeHuzJCCNfxdEO2s4oagbsjOdEpWvzPtPLs1UuBoZjKEE5FtqouiyIlNl ze9s0QyM8JVhUwapIiHHrFtu+A+gNBxNnR16N5SKnUK1ODpqCoOpYVd4X5Kfs1lc 18A9DsDAX7ScimAiKZuoi6x9+Ec70ZhPtwlRl+UG51RbYqr0SQRML+011SfpQPk9 tFc70eLGUa9bU5HtMvXoXzjYADYPPKugLd8qQ09YKeQqeO0eMYf7Uoouz0/YXOQ9 rgDgY4mQsovwWo5+Xijpqf5W75DvPAFz9U/HQz1Kk4wpFXlYkbIyea0vTQmCpeOh zBFjd6o+J5Hpj75t/rSF4QgoFbM9amNsjTFeMxW3c+7u0pun47FtQIGts7AQjZhW I9SkI2/UHITUUtKmDzuSVcEt7lpgtlK5Tc1AoTCs2YY3ku8xNDYNveEKNBqC5M0w mQYuqyHk7pLGM07Z1U2WsrROCO2pXM1E0Ux0RBJltcLSR/NgCXM= =hZ+h -----END PGP SIGNATURE----- --6RJbXby++1bAxkKQ--