gh-153513: Return str and numbers for more Tcl object types in _tkinter#153514
Merged
serhiy-storchaka merged 1 commit intoJul 10, 2026
Merged
Conversation
…_tkinter FromObj() now returns str for the "index", "window", "nsName" and "parsedVarName" object types, whose internal representation is only a context-bound lookup with nothing worth preserving in a Tcl_Obj. An "index" value is one of a small fixed set of enumeration keywords, so its str is interned. A "pixel" screen distance with no unit suffix is screen independent and is now returned as an int or float. A distance with an m/c/i/p suffix needs a Tk_Window to be resolved and is kept as a Tcl_Obj, as are the "dict" and the resource types "color", "border", "font" and "cursor". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documentation build overview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
wantobjectsenabled (the default),FromObj()now converts a few more Tcl object types to the natural Python type instead of wrapping them in an opaque_tkinter.Tcl_Obj.strfor types whose internal representation is only a throwaway, context-bound lookup with nothing worth preserving for a round-trip back to Tcl:index(an enumeration keyword, e.g. the value of-orientor-state),window(e.g.-labelwidget),nsName(a namespace name) andparsedVarName(e.g.-variable). Anindexvalue is always one of a small fixed set of keywords, so the resultingstris interned — equal keywords share a single object.int/floatfor thepixeltype: a screen distance with no unit suffix is already in pixels and screen-independent, so it is returned as a number. A distance with anm/c/i/psuffix depends on the screen resolution and needs aTk_Windowto resolve (not available inFromObj()), so it is kept as aTcl_Obj.Deliberately left as
Tcl_Obj:color,border,fontandcursor, whose internal representation caches an allocated X/font resource that Tk reuses when the object is passed back; anddict, a structured value best consumed with_splitdict().Only the object mode is affected; with
wantobjectsdisabled everything is alreadystr. Verified across Tcl/Tk 8.6, 8.7, 9.0 and 9.1, withwantobjectsboth enabled and disabled. The unit-bearing-distance-stays-Tcl_Objbehavior is Tk 9.0+ only (classic-widgetcgeton Tk < 9 eagerly resolves a unit-bearing distance to an integer pixel count), and thensNameobject type exists only on Tk 9.0+.🤖 Generated with Claude Code