Closed KagaJiankui closed 1 year ago
Somewhere in your setup things got encoded in ascii looks like. You can try to use something like sys.setdefaultencoding('utf-8'), but I can't vouch for the solution I just saw it on a few Stack Overflow posts and it got upvoted.
Hey @KagaJiankui, this is a bug in our Mypy plugin, so I'm going to move this issue to its repo.
@Richardk2n, could you take a look at this one? Thanks!
Decode probably defaults to utf-8 regardless of the encoding the system is set to. Just to confirm: Do you know which encoding your os is set to?
@Richardk2n, it could be this one, according to a quick googling:
https://www.wikiwand.com/en/Code_page_936_(Microsoft_Windows)
the pylsp installation on my computer throws this exception both under system-wide CP936(GBK encoding) and UTF-8 encoding(I used system-wide UTF-8 encoding previously)
Can you check if current master works for you?
My OS uses cp936 encoding (simplified Chinese) by default too. I am using pylsp with Emacs (Eglot).
Every time the buffer (an open file) is saved, the "'utf-8' codec can't decode byte 0xb5 in position 3" error disappears, and mypy works as expected. But when I try to edit the buffer, the error appear again and mypy stopped functioning. I have to save the buffer to make mypy do type checking for me.
It seems that pylsp-mypy only work on saved files, when the OS encoding is not UTF-8.
This problem does not appear on my Linux PC, which uses UTF-8 by default.
Switching to the latest commit does not fix this problem for me.
@zyxir This is an interesting fact. Can you give me the full error (including the line number) for the latest version? If it only happens in live mode it might be related to how the tmp file is saved (and can be avoided for the time being by disabling live mode).
@Richardk2n Currently I don't have access to the Windows PC at home but I will do it when I can. However, it is not easy to produce the full error, as the error is only shown temporarily when the buffer is not saved, and disappears as long as the buffer is saved, so I cannot reproduce it with a saved file. However I can create a short test file to reproduce it, and copy the file as well as the error message here.
Raised following error logs when using python-lsp with jupyter lab 3.5.2:
Installed python-lsp-server extensions:
Platform: Jupyter 3.5.2 ,python 3.10 on Windows 11