Feature or enhancement
A few tkinter query methods with a boolean result return int or a raw Tcl value instead of bool:
Misc.winfo_exists(),Misc.winfo_ismapped()andMisc.winfo_viewable()returnint(they usegetint()).Text.edit_modified()returns the raw result ofedit modified, so its type depends onwantobjects:intwhen it is on,str('0'/'1') when it is off.
All the other boolean-valued query methods already return a proper bool: Misc.winfo_colormapfull(), winfo_isdark(), tk_busy_status(), wm_overrideredirect(), wm_stackorder(isabove/isbelow), Text.compare(), edit_canundo(), edit_canredo(), pendingsync(), the selection_present()/selection_includes()/validate() methods of Entry, Listbox and Spinbox, PhotoImage.transparency_get(), ttk.Widget.instate(), and the ttk.Treeview predicates (haschildren(), visible(), detached(), cellselection_includes(), cellselection_present(), tag_cell_has()).
I propose to make the four outliers consistent:
- the three
winfo_*methods usegetboolean()instead ofgetint(); edit_modified()coerces the query result withgetboolean()(the setter form, with an argument, is unchanged).
bool is a subclass of int, so existing boolean and arithmetic uses keep working; only code relying on the exact int/str type of the result is affected.
The winfo_* methods have coerced the result to int since the initial revision of tkinter, predating the bool type (added in Python 2.3) -- at the time there was no boolean type to return, and the choice was never revisited when bool was introduced.
Linked PRs
- gh-153422: Return bool from some tkinter query methods #153429
- [3.15] gh-153422: Assert bool return type in tkinter tests (GH-153429) #153439
- [3.14] gh-153422: Assert bool return type in tkinter tests (GH-153429) (GH-153439) #153442
- [3.13] gh-153422: Assert bool return type in tkinter tests (GH-153429) (GH-153439) #153443