-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Tkinter: getint and getdouble should support Tcl_Obj #68068
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
getint, getdouble and getboolean were thin wrappers around Tcl functions that converted string result of Tcl call to specified Python type. Since 2.3 _tkinter can return not only string, but int, float, etc and Tcl_Obj (if wantobject is True). getXXX methods was updated to work with respective automatically converted types (getint with int, etc), but they don't work with general Tcl_Obj, so can't be applied to the result of _tkinter call in general case. As a workaround you should use int(str(value)) or like. Support of Tcl_Obj in getbool was added in bpo-15133. Proposed patch adds support of Tcl_Obj in getint and getdouble and int in getdouble. It also restores the use of getint and getdouble in Tkinter. |
I don't quite understand this, but I think I should. Here are preliminary questions.
How does this match getint and getdouble being synonyms for builtins?
|
The benefit is that widget.tk.getint(widget.tk.call(...)) (and widget.getint(widget.call(...))) always works when it makes sense. Currently it works for integers and strings. If the result of Tcl call becomes some specific type in new Tcl version, this needs a workaround with converting to str, as you can see in IDLE code. User code with this patch will become more robust against future Tcl/Tk changes. And actually against changes that already happen in recent Tcl versions. Many user code that worked with 8.3 or 8.4 needed an update to work with 8.5 or 8.6. With this patch they perhaps need less changes.
Usually not.
It is optional. It is is just a demonstration how the code can be made simpler and more robust.
There are different functions on different levels. There are tkapp methods in _tkinter.c. There are Misc methods in tkinter.py (added in changesets 73dd2a979857 and 273451892327). They originally was wrappers around tkapp methods. There are module-level functions in tkinter.py. They were converted to aliases of int and float in 34cca832a4af.
Unfortunately all these functions are not documented. |
I meant that the only difference (except that now Tkinter can work in cases where it failed before) is that that some exceptions can change its type from ValueError to TclError. But first, these exception are unlikely raised, and second, getint() and getdouble() are used to convert the result of call(), that can raise a TclError, so this doesn't add new exception type. However, to decrease even such minor probability of the breakage, the patch for 3.4 and 2.7 uses widget.getint() instead of widget.tk.getint(). This wrapper converts TclError to ValueError. |
New changeset cb80dd82d3da by Serhiy Storchaka in branch 'default': |
Committed in the default branch only. If other issues with Tcl/Tk 8.5 or 8.6 will be reported, we could apply general solution instead of particular workarounds in maintained branches too. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: