public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Michael Frysinger <vapier@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb: copyright: make file header scan a bit more pythonic
Date: Wed, 26 Oct 2022 10:11:49 +0000 (GMT)	[thread overview]
Message-ID: <20221026101149.968513857C72@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=99033a63c7ba0997ef737392eef15337d6783078

commit 99033a63c7ba0997ef737392eef15337d6783078
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Sat Jan 1 13:08:20 2022 -0500

    gdb: copyright: make file header scan a bit more pythonic
    
    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.
    
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 gdb/copyright.py | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/gdb/copyright.py b/gdb/copyright.py
index 8d623e6f5c7..040fed18708 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 > MAX_LINES:
+                break
     return False

                 reply	other threads:[~2022-10-26 10:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221026101149.968513857C72@sourceware.org \
    --to=vapier@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).