Skip to content

Commit

Permalink
avoid lib2to3
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Jan 5, 2025
1 parent 3dc14b6 commit aca208a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class documentation for more information.
import ast
from configparser import ConfigParser as SafeConfigParser, Error

import chardet
import pycodestyle


Expand Down Expand Up @@ -4523,14 +4524,12 @@ def is_python_file(filename):
return True

try:
with open_with_encoding(
filename,
limit_byte_check=MAX_PYTHON_FILE_DETECTION_BYTES) as f:
with open_with_encoding(filename) as f:
text = f.read(MAX_PYTHON_FILE_DETECTION_BYTES)
if not text:
return False
first_line = text.splitlines()[0]
except (IOError, IndexError):
except (IOError, IndexError, UnicodeDecodeError):
return False

if not PYTHON_SHEBANG_REGEX.match(first_line):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


INSTALL_REQUIRES = (
['pycodestyle >= 2.8.0', 'toml']
['pycodestyle >= 2.8.0', 'toml', 'chardet']
)


Expand All @@ -30,7 +30,7 @@ def version():
'to the PEP 8 style guide',
long_description=readme.read(),
license='Expat License',
author='Hideo Hattori',
author='Hideo Hattoriは',
author_email='hhatto.jp@gmail.com',
url='https://github.com/hhatto/autopep8',
classifiers=[
Expand Down
2 changes: 2 additions & 0 deletions test/iso_8859_1.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# -*- coding: iso-8859-1 -*-

s = "¿¿¿¿¿"
2 changes: 1 addition & 1 deletion test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_detect_encoding(self):

def test_detect_encoding_with_cookie(self):
self.assertEqual(
'iso-8859-1',
'ISO-8859-1',
autopep8.detect_encoding(
os.path.join(ROOT_DIR, 'test', 'iso_8859_1.py')))

Expand Down

0 comments on commit aca208a

Please sign in to comment.