Closed villares closed 2 years ago
Hmmm, interesting. Great find! This does need to work for folks who type comments in non-ascii characters.
I can't reproduce it on my Mac though. Is this a Windows thing? What happens if you put the code in a file and run it with run_sketch and not through Thonny? I don't understand that last line of the stack trace. Why does f.read()
go to cp1252.py in the Thonny source code?
Yeah! I was on a Windows (and at home on Linux I think it didn't happen). Strange stuff... could be a Thonny issue? I'll try to test more.
Maybe a Thonny issue on Windows? Let me know what you figure out.
I did some Googling because I was curious and I found a few things. This is an encoding issue, and maybe py5 needs to be explicit about reading and writing files with a particular encoding on Windows.
https://github.com/thonny/thonny/issues/2022 https://stackoverflow.com/questions/26324622/what-characters-do-not-directly-map-from-cp1252-to-utf-8
I can now reproduce this, and I have a potential solution.
My fix seems to work. I just needed to add encoding='utf8'
to two locations.
I need to test it more and do some investigation to make sure there isn't a third place that also needs the same adjustment.
You have found a lot of bugs lately! This is appreciated. This latest bug is particularly important because it hinders non-english speakers from using fully using Thonny in their own language. BTW, this bug had nothing to do with comments or triple quoted strings. If Á
appeared anywhere in the file, it wouldn't work. You can create variables or functions with Á
in the name if you like.
Hmmm, I have found a third place. If a json file contained an Á
character and you tried to read it with py5.load_json()
, you would get the same error.
This is going to require a closer look. I thought my Python encoding problems were over since I stopped using Python 2.7. Guess I was wrong!
Python feature for v 3.15: https://peps.python.org/pep-0686/
We can't wait that long...working on a fix now.
The translator utilities also suffered from this problem.
This seems to be fixed. I tested everything I can think of and can't find a way to break py5 with an 'Á'
character.
py5.version: '0.8.0a2' To reproduce:
Resulting exception:
Surprisingly,
Á
will crash, but theá
character won't crash...I stumbled upon this because I have a sketch named "Árvore recursiva" (recursive tree) that crashes, while "Lousa mágica" (magic blackboard) didn't crash...