summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2021-01-07 08:16:57 -0800
committerAnthony Sottile <asottile@umich.edu>2021-01-07 08:16:57 -0800
commitdde53f69f11571161c1db7c43ebfc3cfdfcc6f96 (patch)
tree7d1d06576276b9a20bdcba7104c552218d069a62
parent9dd78b97dea0e943300c92c853d6869e7fe41299 (diff)
downloadpep8-dde53f69f11571161c1db7c43ebfc3cfdfcc6f96.tar.gz
use tokenize.open to avoid incorrect line endings at beginning of file
-rwxr-xr-xpycodestyle.py6
-rw-r--r--testsuite/crlf.py3
2 files changed, 5 insertions, 4 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 17fac7a..2f4313f 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -1814,10 +1814,8 @@ else:
def readlines(filename):
"""Read the source code."""
try:
- with open(filename, 'rb') as f:
- (coding, lines) = tokenize.detect_encoding(f.readline)
- f = TextIOWrapper(f, coding, line_buffering=True)
- return [line.decode(coding) for line in lines] + f.readlines()
+ with tokenize.open(filename) as f:
+ return f.readlines()
except (LookupError, SyntaxError, UnicodeError):
# Fall back if file encoding is improperly declared
with open(filename, encoding='latin-1') as f:
diff --git a/testsuite/crlf.py b/testsuite/crlf.py
new file mode 100644
index 0000000..41f0d0f
--- /dev/null
+++ b/testsuite/crlf.py
@@ -0,0 +1,3 @@
+'''\
+test
+'''