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

Type-annotated "encoding" field crashes isort #1027

Closed
srittau opened this issue Oct 9, 2019 · 2 comments · Fixed by #1031
Closed

Type-annotated "encoding" field crashes isort #1027

srittau opened this issue Oct 9, 2019 · 2 comments · Fixed by #1031

Comments

@srittau
Copy link
Contributor

srittau commented Oct 9, 2019

This came up while trying to enforce isort imports in typeshed. Please consider the following file:

class X:
    encoding: str

(The actual file it stumbles over is stdlib/3/io.pyi.)

Running isort 4.3.21 with Python 3.7 against this fails with the following traceback:

Traceback (most recent call last):
  File "./.venv/bin/isort", line 10, in <module>
    sys.exit(main())
  File "/home/srittau/.venv/lib/python3.7/site-packages/isort/main.py", line 379, in main
    for sort_attempt in attempt_iterator:
  File "/home/srittau/.venv/lib/python3.7/site-packages/isort/main.py", line 377, in <genexpr>
    attempt_iterator = (sort_imports(file_name, **arguments) for file_name in file_names)
  File "/home/srittau/.venv/lib/python3.7/site-packages/isort/main.py", line 88, in sort_imports
    result = SortImports(file_name, **arguments)
  File "/home/srittau/.venv/lib/python3.7/site-packages/isort/isort.py", line 114, in __init__
    with io.open(file_path, encoding=file_encoding, newline='') as file_to_import_sort:
LookupError: unknown encoding: str
@srittau
Copy link
Contributor Author

srittau commented Oct 10, 2019

Correction: The file that triggered the original problem was stdlib/3/encodings/__init__.pyi.

srittau added a commit to python/typeshed that referenced this issue Oct 10, 2019
@hauntsaninja
Copy link

Hello! Would it be possible to cut a new release that includes this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants