From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org 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 From: Mike Frysinger 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-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,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: --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--