Skip to content

open file with encoding#374

Merged
DonJayamanne merged 2 commits into
DonJayamanne:masterfrom
IgorNovozhilov:0.4.1/bugfix/igornovozhilov/issue372
Oct 12, 2016
Merged

open file with encoding#374
DonJayamanne merged 2 commits into
DonJayamanne:masterfrom
IgorNovozhilov:0.4.1/bugfix/igornovozhilov/issue372

Conversation

@IgorNovozhilov
Copy link
Copy Markdown
Contributor

Fixed #372 -"UnicodeDecodeError: 'charmap' codec can't decode"

Comment thread pythonFiles/jedi/api/__init__.py Outdated

if source is None:
with open(path) as f:
with open(path, encoding=encoding) as f:
Copy link
Copy Markdown
Owner

@DonJayamanne DonJayamanne Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IgorNovozhilov how about adding a try..except.
If the above (and below) code doesn't work, then try opening with the encoding.
I prefer that approach as that will leave it backward compatible (ensuring we don't introduce any other issues).
If you can make that change I can accept this and create a build soon.

here's what I'm suggesting:

try:
    with open(path) as f:
        source = f.read()
except UnicodeDecodeError:
    with open(path, encoding=encoding) as f:
        source = f.read()

Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready

@DonJayamanne DonJayamanne merged commit 9f023f3 into DonJayamanne:master Oct 12, 2016
@DonJayamanne
Copy link
Copy Markdown
Owner

Thanks.

DonJayamanne added a commit that referenced this pull request Oct 12, 2016
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 this pull request may close these issues.

2 participants