Skip to content

Fix decode error on non-utf8 environments #60

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

Conversation

gashihiko
Copy link

@gashihiko gashihiko commented Apr 12, 2023

Added encoding option when opening the tmpFile.
Maybe Fixes #55
The bug that shows unnecessary diagnostics like LSP: mypy: can't decode file 'path/to/file.py': 'utf-8' codec can't decode byte 0x82 in position 52: invalid st... could be reproduced on Japanese Windows 10 when the file includes multi byte characters.
By default, open() encodes a file in cp932 on my environment.
The mypy causes the error when decode_python_encoding() in util.py tries to decode the tmp file by utf-8 codec. It is the default behavior unless the file encoding comment(e.g. # coding: latin-1) is written in the code.

@Richardk2n
Copy link
Member

Was thinking, that the writing could be the issue. Thanks for writing it up. Just to be sure: you could reproduce the error and this change got rid of it?

@gashihiko
Copy link
Author

Was thinking, that the writing could be the issue. Thanks for writing it up. Just to be sure: you could reproduce the error and this change got rid of it?

Yes, the change got rid of the error.

@Richardk2n Richardk2n merged commit 6fd72c3 into python-lsp:master Apr 12, 2023
@Richardk2n
Copy link
Member

Richardk2n commented Apr 12, 2023

Thank you very much

@gashihiko gashihiko deleted the fix/decode-error-on-non-utf-8-environment branch April 12, 2023 18:21
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.

Bug: Failed to load hook pylsp_lint: 'utf-8' codec can't decode byte 0xb5 in position 3
2 participants