diff options
author | Mike Frysinger <vapier@gentoo.org> | 2022-01-01 13:08:20 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2022-10-26 14:41:40 +0545 |
commit | 99033a63c7ba0997ef737392eef15337d6783078 (patch) | |
tree | 7e68f13928eaee5c6eb84038c63ff55df147d435 /gdb | |
parent | e5fbca55b28b77eced290e4e681f1d5cd3dafe98 (diff) | |
download | gdb-99033a63c7ba0997ef737392eef15337d6783078.zip gdb-99033a63c7ba0997ef737392eef15337d6783078.tar.gz gdb-99033a63c7ba0997ef737392eef15337d6783078.tar.bz2 |
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>
Diffstat (limited to 'gdb')
-rwxr-xr-x | gdb/copyright.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/gdb/copyright.py b/gdb/copyright.py index 8d623e6..040fed1 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 |