Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use tokenize.open to avoid incorrect line endings at beginning of file #976

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
'''