bpo-13153: Use OS native encoding for converting between Python and Tcl. by serhiy-storchaka · Pull Request #16545 · python/cpython (original) (raw)

This works better than I expected. Pasting an astral char not only does not raise and exit, but the actual char is displayed if the font + OS extension supports it, otherwise a replacement box. I see the computer emoji below.

>>> print('💻', '\U0001f4bb')  # 💻 was pasted.
💻 💻

It also fixes user printing of astral chars (bpo 2274), either as the char or replacement char, and tracebacks with astral chars (bpo 36698). I presume it will fix display of file names and contents with astral chars, and will test later.

There is also a problem that I did not expect. Editing code past astral chars, on the same line, is discombobulated. For me, on Windows, the insert cursor | is displayed two chars to the left of where it should be for each astral char it follows on the same line. For instance, to change the f in '\U00|01f4bb', position the | cursor as shown, hit DEL, and the replacement. Backspace and replacement will not work correctly. Chars immediately past an astral cannot be edited at all. This is better than IDLE closing, but if, as I suspect, we cannot change this, the IDLE doc should mention that astral literals disable proper editing on the remainder of the physical line.