Skip to content

Commit

Permalink
use tokenize.open to avoid incorrect line endings at beginning of file
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jan 7, 2021
1 parent 9dd78b9 commit dde53f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,10 +1814,8 @@ def readlines(filename):
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:
Expand Down
3 changes: 3 additions & 0 deletions testsuite/crlf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''\
test
'''

0 comments on commit dde53f6

Please sign in to comment.