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

pie_slice in isort>=4.3.5 no longer sets sys.setdefaultencoding('utf-8') #842

Closed
ericboyangan opened this issue Feb 25, 2019 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@ericboyangan
Copy link

ericboyangan commented Feb 25, 2019

Hi! We're experiencing a new error in a Python 2.7 lint test that I believe was caused by bumping our isort from 4.3.4 to 4.3.5 (by way of flake8-isort's call to SortImports with both file_path and file_contents).

I see that the 4.3.5 version of pie_slice.py no longer calls sys.setdefaultencoding('utf-8') in python 2; which means source code containing non-ASCII now errors with UnicodeDecodeError on line 129 of isort.py. In general, IIUC, it seems file_contents cannot be a string with non-ASCII characters.

Wondering what you think would be the best resolution for this issue? And thank you so much for the great tool all these years!

@cleder
Copy link

cleder commented Feb 27, 2019

File "/home/vagrant/venv/lib/python2.7/site-packages/isort/isort.py", line 108, in __init__
    if file_contents is None or ("isort:" + "skip_file") in file_contents:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1988: ordinal not in range(128)

isort==4.3.9

@timothycrosley timothycrosley added the bug Something isn't working label Mar 3, 2019
@timothycrosley
Copy link
Member

This has been fixed in the latest 4.3.10 release.
https://github.com/timothycrosley/isort/releases/tag/4.3.10

Thanks!

~Timothy

@bcroq
Copy link

bcroq commented Mar 5, 2019

I still get @cleder 's error using isort 4.3.10 when using flake8-isort:

  File "/home/bcq/.virtualenvs/.../lib/python2.7/site-packages/isort/isort.py", line 108, in __init__
    if file_contents is None or ("isort:" + "skip_file") in file_contents:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1050: ordinal not in range(128)

@bcroq
Copy link

bcroq commented Mar 6, 2019

@timothycrosley here is how I get this issue.

First, create a test.py Python file containing:

# coding: utf-8

x = 'testé'

Then run isort - < test.py.

Here is what I get with isort 4.3.5 to 4.3.10:

Traceback (most recent call last):
  File "/home/bcq/.../bin/isort", line 11, in <module>
    load_entry_point('isort', 'console_scripts', 'isort')()
  File "/home/bcq/git/isort/isort/main.py", line 331, in main
    SortImports(file_contents=sys.stdin.read(), write_to_stdout=True, **arguments)
  File "/home/bcq/git/isort/isort/isort.py", line 108, in __init__
    if file_contents is None or ("isort:" + "skip_file") in file_contents:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 26: ordinal not in range(128)

No problem with isort 4.3.4.

@timothycrosley
Copy link
Member

Hi @bcroq,

Thanks for providing some additional repro steps! Can you try the just release 4.3.11 and see if it resolves this issue for you? https://github.com/timothycrosley/isort/releases/tag/4.3.11

Thanks!

~Timothy

@bcroq
Copy link

bcroq commented Mar 6, 2019

@timothycrosley 4.3.11 does not solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants