python-lsp / pylsp-mypy

Mypy plugin for the Python LSP Server.
MIT License
130 stars 37 forks source link

Fix decode error on non-utf8 environments #60

Closed gashihiko closed 1 year ago

gashihiko commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thank you very much