-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Accessing a tkinter object's string representation converts the object to a string on Windows #101830
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
Comments
To offer some background: Tcl usually calls this side effect “shimmering”. The Tcl syntax documentation does not seem to explain it, but the C API documentation gives some hints: https://www.tcl-lang.org/man/tcl8.6/TclLib/Object.htm explains that a Tcl value has a “string representation” (modified UTF-8 bytes) and up to one “internal representation” depending on its type; and in https://www.tcl-lang.org/man/tcl8.6/TclLib/StringObj.htm there is a distinction between a “Unicode representation” (a sequence of 16-bit or 32-bit codepoints) which is the internal representation of a value with the “string” type, versus the “string representation” for values of any type. So |
Accessing the Tkinter object's string representation no longer converts the underlying Tcl object to a string on Windows.
Thank you, I overlook this effect. The reason of using Tcl_GetUnicodeFromObj/Tcl_NewUnicodeObj on Windows and Tcl_GetStringFromObj/Tcl_NewStringObj on other platforms is that by default Tcl does not support Unicode outside of the BMP, but the underlying graphic system may support if the data is present in native multibyte encoding (UTF16 on Windows, UTF8 on other platforms). Tcl cannot correctly convert between UTF16 and UTF8 representations of non-BMP characters, so we need to create Tcl objects in the appropriate representation. Using Tcl_GetUnicodeFromObj only for Tcl objects with the “Unicode representation” should fix most issues. It will create a new issue: if the Tcl object is compound and contains strings with non-BMP characters, Tcl_GetStringFromObj will produce result containing broken UTF8. This is uncommon case, because Tcl "list" objects are represented as tuples in Python, but Tcl "dict" objects are represented as Tcl_Objs. I do not know whether Tcl "dict" objects are used in Tk. Copying the object before passing calling Tcl_GetUnicodeFromObj could solve this issue, but this is very complex solution. I think that we should fix regression in common cases and leave possible complicated solution of more subtle problem until we encounter it in real world. |
Accessing the Tkinter object's string representation no longer converts the underlying Tcl object to a string on Windows.
Accessing the Tkinter object's string representation no longer converts the underlying Tcl object to a string on Windows. (cherry picked from commit f4ddaa3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Accessing the Tkinter object's string representation no longer converts the underlying Tcl object to a string on Windows.
Accessing the Tkinter object's string representation no longer converts the underlying Tcl object to a string on Windows.
Accessing the Tkinter object's string representation no longer converts the underlying Tcl object to a string on Windows.
Introduced in #16545
Affects Python 3.7+ on Windows only
The
FromObj
function in_tkinter.c
attempt to convert aTcl_Obj
to an equivalent Python object if possible, and otherwise returns a_tkinter.Tcl_Obj
with thetypename
attribute set to the original object's type.However, on Windows, accessing the resulting object's string representation calls
Tcl_GetUnicodeFromObj
, which converts theTcl_Obj
to aString
. This side effect isn't mentioned in the Tcl documentation, but is in the Tcl source code. As a result, retrieving the same tk property afterwards will return a Python string instead.Minimal example:
Possible solutions:
unicodeFromTclObj
should copy the object before passing callingTcl_GetUnicodeFromObj
, or handle Unicode without it like on other platforms.Linked PRs
The text was updated successfully, but these errors were encountered: