Skip to content

Commit dde53f6

Browse files
committed
use tokenize.open to avoid incorrect line endings at beginning of file
1 parent 9dd78b9 commit dde53f6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pycodestyle.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,10 +1814,8 @@ def readlines(filename):
18141814
def readlines(filename):
18151815
"""Read the source code."""
18161816
try:
1817-
with open(filename, 'rb') as f:
1818-
(coding, lines) = tokenize.detect_encoding(f.readline)
1819-
f = TextIOWrapper(f, coding, line_buffering=True)
1820-
return [line.decode(coding) for line in lines] + f.readlines()
1817+
with tokenize.open(filename) as f:
1818+
return f.readlines()
18211819
except (LookupError, SyntaxError, UnicodeError):
18221820
# Fall back if file encoding is improperly declared
18231821
with open(filename, encoding='latin-1') as f:

testsuite/crlf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'''\
2+
test
3+
'''

0 commit comments

Comments
 (0)