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(-) > > > > 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 = 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 > 50: > > I was checking the warnings given by flake8: > > copyright.py:143:5: F841 local variable 'MAX_LINES' is assigned to but never used > > I think this `50` was meant to be MAX_LINES. You might as well change > the code to use it. LGTM in any case: > > Approved-By: Simon Marchi i had noticed that locally already and looks like i forgot to send out a v2 -mike