diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-10-26 10:34:56 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-10-26 10:34:56 -0400 |
commit | 8cd2b7477b1e58cdace3ebcffc343d45a1f4b729 (patch) | |
tree | 1379ba22f26273ff461312b2e1e709926a6a3882 /igor.py | |
parent | af073c55208a2ae1fc488adec167f55ef28f9d15 (diff) | |
download | python-coveragepy-8cd2b7477b1e58cdace3ebcffc343d45a1f4b729.tar.gz |
Use with-open everywhere
Diffstat (limited to 'igor.py')
-rw-r--r-- | igor.py | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -168,18 +168,19 @@ def do_check_eol(): checked.add(fname) line = None - for n, line in enumerate(open(fname, "rb"), start=1): - if crlf: - if "\r" in line: - print("%s@%d: CR found" % (fname, n)) - return - if trail_white: - line = line[:-1] - if not crlf: - line = line.rstrip('\r') - if line.rstrip() != line: - print("%s@%d: trailing whitespace found" % (fname, n)) - return + with open(fname, "rb") as f: + for n, line in enumerate(f, start=1): + if crlf: + if "\r" in line: + print("%s@%d: CR found" % (fname, n)) + return + if trail_white: + line = line[:-1] + if not crlf: + line = line.rstrip('\r') + if line.rstrip() != line: + print("%s@%d: trailing whitespace found" % (fname, n)) + return if line is not None and not line.strip(): print("%s: final blank line" % (fname,)) |