This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tkinter: getint and getdouble should support Tcl_Obj
Type: enhancement Stage: resolved
Components: Extension Modules, Tkinter Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2015-04-07 08:41 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter_getxxx_tclobj.patch serhiy.storchaka, 2015-04-07 08:41 review
tkinter_getxxx_tclobj-3.4.patch serhiy.storchaka, 2015-04-24 12:09 review
tkinter_getxxx_tclobj-2.7.patch serhiy.storchaka, 2015-04-24 12:09 review
Messages (6)
msg240196 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-04-07 08:41
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 issue15133. 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.
msg240221 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-04-07 18:09
I don't quite understand this, but I think I should.  Here are preliminary questions.

0.  It seems that this pushes conversions from python code (app.py, tkinter.py) to C (_tkinter.py).  Correct?  What is being gained from a user viewpoint?

1. "getint, getdouble and getboolean were thin wrappers around Tcl functions that converted string result of Tcl call to specified Python type."

How does this match getint and getdouble being synonyms for builtins?
-    getint = int
-    getdouble = float
Or were 'int' and 'float' overriden before this?

2. Does the change break existing code?  In particular, is the idlelib change necessary or optional?

3. Should there be a doc change, at least in docstrings?
msg240223 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-04-07 18:57
> 0.  It seems that this pushes conversions from python code (app.py, tkinter.py) to C (_tkinter.py).  Correct?  What is being gained from a user viewpoint?

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.

> 2. Does the change break existing code?

Usually not.

>  In particular, is the idlelib change necessary or optional?

It is optional. It is is just a demonstration how the code can be made simpler and more robust.

> How does this match getint and getdouble being synonyms for builtins?
> -    getint = int
> -    getdouble = float
> Or were 'int' and 'float' overridden before this?

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.

> 3. Should there be a doc change, at least in docstrings?

Unfortunately all these functions are not documented.
msg241935 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-04-24 12:09
>> 2. Does the change break existing code?
> 
> Usually not.

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.
msg242654 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-05-06 11:00
New changeset cb80dd82d3da by Serhiy Storchaka in branch 'default':
Issue #23880: Tkinter's getint() and getdouble() now support Tcl_Obj.
https://hg.python.org/cpython/rev/cb80dd82d3da
msg242655 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-06 11:03
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.
History
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68068
2015-05-06 11:03:09serhiy.storchakasetstatus: open -> closed
messages: + msg242655

assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2015-05-06 11:00:31python-devsetnosy: + python-dev
messages: + msg242654
2015-04-24 12:09:58serhiy.storchakasetfiles: + tkinter_getxxx_tclobj-2.7.patch
2015-04-24 12:09:42serhiy.storchakasetfiles: + tkinter_getxxx_tclobj-3.4.patch
2015-04-24 12:09:16serhiy.storchakasetmessages: + msg241935
2015-04-07 18:57:40serhiy.storchakasetmessages: + msg240223
2015-04-07 18:09:05terry.reedysetmessages: + msg240221
2015-04-07 08:41:34serhiy.storchakasetnosy: + terry.reedy
2015-04-07 08:41:03serhiy.storchakacreate