From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id DD723385841F for ; Wed, 26 Oct 2022 10:11:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD723385841F 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 6D4DD340F46; Wed, 26 Oct 2022 10:11:16 +0000 (UTC) Date: Wed, 26 Oct 2022 14:41:52 +0545 From: Mike Frysinger To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb: copyright: make file header scan a bit more pythonic Message-ID: Mail-Followup-To: Simon Marchi , 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="w/i3wvFJqluvmfPX" Content-Disposition: inline In-Reply-To: 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: --w/i3wvFJqluvmfPX Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 24 Oct 2022 21:16, Simon Marchi wrote: > 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(-) > >=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: >=20 > I was checking the warnings given by flake8: >=20 > copyright.py:143:5: F841 local variable 'MAX_LINES' is assigned to but ne= ver used >=20 > I think this `50` was meant to be MAX_LINES. You might as well change > the code to use it. LGTM in any case: >=20 > Approved-By: Simon Marchi i had noticed that locally already and looks like i forgot to send out a v2 -mike --w/i3wvFJqluvmfPX Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmNY9lQACgkQQWM7n+g3 9YEPJA/+OcWpFQT6ujYPzQ5u7FHijzloPRCyGCBeaszP+E7mi4rQt6V3DjrlFG58 9J0J5Rrfz/J6QrnU7WV4jCCyX37wFiDRSJM8A/F74w6GW78y8dKy/xT6BpuMjL94 pejaSFFmdgpCovcZvIwbpzUdc8oRGHOmleocUMg1pD41tLkzjr1bVslzXYXm+DV3 t0CV5XtGjkTYa1vYk1DFbSVd4ZbLgmLrQvwasd65TsF2hJBVRjGVvWKhpR6xfVLY SNdUxtAEH+8YAhkYDZkAfX2UZfN7FYHMRGjauxeqU2kAHhXAhB6kHpGRwyhZHGIr umG6yUKEQIX7Q9tr4U4rLxVDl5tI1OmsmovhArUl0HXyFRqh3CpZATdlPwC+0ee6 zED3nBKfB2XlwqmIVVlzz4caoL/6OwW6pNGavWu9udn7HxX6ZS38Qnw1tjRzJauN QEHdmOEkq+KGr4125NCAGJk+cOPJqA48U/EmP7Q95w87rJt6RU2nhPXH7alBZ1vM Gm//gG08XAtnPkPVe0dQIqcJHHGGwgMqXxgyDhztgPC1DUdUC2ztudvyv8iXw6Fk 39af8DB/mYG5XF8NdSiC288zDSQWnBR37vbLndXN2QyrMKwY9kQblyAQoY238HUo 7JxFw6teB8veNlMTV/UsdeoTnepTxJ0xVSyI8yHqcYhszFCD4z0= =+nHR -----END PGP SIGNATURE----- --w/i3wvFJqluvmfPX--