Message ID | SN4P221MB0682A6E723BF55D3807B1BBBA0689@SN4P221MB0682.NAMP221.PROD.OUTLOOK.COM |
---|---|
State | Changes Requested |
Headers | show |
Series | support ignore-indent for check-package configs | expand |
Hello James, On Sat, 29 Apr 2023 14:12:02 -0400 James Knight <james.d.knight@live.com> wrote: > Cleanup the implementation for reading lines by having files processed > in context managers and utilizing the iterable file object for line > reading (instead of needing to call `readlines()`). > > Signed-off-by: James Knight <james.d.knight@live.com> > --- > utils/check-package | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/utils/check-package b/utils/check-package > index 83b9750f5a9c181dc96dcba508682776a600aac5..db3a00b524bc2c2aa663d3621c94fb11a6db7cb3 100755 > --- a/utils/check-package > +++ b/utils/check-package > @@ -229,16 +229,18 @@ def check_file_using_lib(fname): > nwarnings += warn > > lastline = "" > - for lineno, text in enumerate(open(fname, "r", errors="surrogateescape").readlines()): > - nlines += 1 > - for name, cf in objects: > - if cf.disable.search(lastline): > - continue > - warn, fail = print_warnings(cf.check_line(lineno + 1, text), name in xfail) > - if fail > 0: > - failed.add(name) > - nwarnings += warn > - lastline = text > + with open(fname, "r", errors="surrogateescape") as f: > + for lineno, text in enumerate(f): > + nlines += 1 > + for name, cf in objects: > + if cf.disable.search(lastline): > + continue > + line_sts = cf.check_line(fstate, lineno + 1, text) This variable "fstate" doesn't exist as of PATCH 1/4. I wanted to apply only this patch for now, as I'm not sure about PATCH 2/4 to PATCH 4/4, but PATCH 1/4 on its own doesn't work. Could you have a look? Thanks! Thomas
diff --git a/utils/check-package b/utils/check-package index 83b9750f5a9c181dc96dcba508682776a600aac5..db3a00b524bc2c2aa663d3621c94fb11a6db7cb3 100755 --- a/utils/check-package +++ b/utils/check-package @@ -229,16 +229,18 @@ def check_file_using_lib(fname): nwarnings += warn lastline = "" - for lineno, text in enumerate(open(fname, "r", errors="surrogateescape").readlines()): - nlines += 1 - for name, cf in objects: - if cf.disable.search(lastline): - continue - warn, fail = print_warnings(cf.check_line(lineno + 1, text), name in xfail) - if fail > 0: - failed.add(name) - nwarnings += warn - lastline = text + with open(fname, "r", errors="surrogateescape") as f: + for lineno, text in enumerate(f): + nlines += 1 + for name, cf in objects: + if cf.disable.search(lastline): + continue + line_sts = cf.check_line(fstate, lineno + 1, text) + warn, fail = print_warnings(line_sts, name in xfail) + if fail > 0: + failed.add(name) + nwarnings += warn + lastline = text for name, cf in objects: warn, fail = print_warnings(cf.after(), name in xfail)
Cleanup the implementation for reading lines by having files processed in context managers and utilizing the iterable file object for line reading (instead of needing to call `readlines()`). Signed-off-by: James Knight <james.d.knight@live.com> --- utils/check-package | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)