classification
Title: Refactor dict result handling in Tkinter
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.5, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: gpolo, python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2014-08-19 06:16 by serhiy.storchaka, last changed 2014-09-06 19:53 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter_splitdict.diff serhiy.storchaka, 2014-08-19 06:16 review
tkinter_splitdict_2.patch serhiy.storchaka, 2014-08-21 05:55 review
tkinter_splitdict_3.patch serhiy.storchaka, 2014-09-06 07:28 review
Messages (9)
msg225515 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-19 06:16
Proposed patch refactors code which converts the result of Tcl call to Python dict. Added new private function _splitdict() which does this in more robust manner.

Also this patch fixes a bug in Treeview.heading(). The heading subcommand of ttk::treeview return options dict in which one key surprisingly was not '-' prefixed.

% ttk::treeview t
% .t heading #0
-text {} -image {} -anchor center -command {} state {}

Current code unconditionally cuts "s" from the "state" key.

>>> from tkinter import ttk
>>> t = ttk.Treeview()
>>> t.heading('#0')
{'anchor': 'center', 'tate': '', 'image': '', 'text': '', 'command': ''}
msg225594 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-20 23:39
The patch expands and fixes buggy ttk._dict_from_tcltuple, renames and moves it to tkinter._splitdict, and replace 4 similar blocks of code in tkinter with calls to _splitdict.  Review published. The only substantive comment is about keeping the test, in a new location. Aside from the comments, this is a nice code improvement.
msg225597 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-21 05:55
The patch expands and fixes buggy ttk._dict_from_tcltuple, renames and moves it to tkinter._splitdict

There are differences between these functions. tkinter._splitdict calls splitlist on its argument, ttk._dict_from_tcltuple requires argument to be tuple/list. ttk._dict_from_tcltuple calls tclobjs_to_py on the result, tkinter._splitdict left it to the caller. Instead tkinter._splitdict allows you to specify custom function for dict values convertion.

Updated patch addresses Terry's comments.

Function name is matter of bakeshedding.
msg226406 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-05 08:07
If there are no objections I'll commit the patch soon.
msg226447 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-09-05 19:34
I made two style comments, one an expansion of a previous comment.  I believe all other previous comments were handled ok.
msg226474 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 07:28
Thank you Terry. Fixed style in two methods, added a summary to Treeview.set() docstring and changed returns/sets to return/set. But I disagree with other suggestions. Return value of 3-arg call is insignificant implementation detail. In any case these changes are irrelevant to this issue.
msg226500 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-09-06 18:07
looks good to commit.
msg226508 - (view) Author: Roundup Robot (python-dev) Date: 2014-09-06 19:52
New changeset 7b0fdc1e917a by Serhiy Storchaka in branch '2.7':
Issue #22226: Added private function _splitdict() in the Tkinter module.
http://hg.python.org/cpython/rev/7b0fdc1e917a

New changeset f89995a4ec11 by Serhiy Storchaka in branch '3.4':
Issue #22226: Added private function _splitdict() in the Tkinter module.
http://hg.python.org/cpython/rev/f89995a4ec11

New changeset 11cf18ec1900 by Serhiy Storchaka in branch 'default':
Issue #22226: Added private function _splitdict() in the Tkinter module.
http://hg.python.org/cpython/rev/11cf18ec1900
msg226509 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 19:53
Thank you Terry for your review.
History
Date User Action Args
2014-09-06 19:53:17serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg226509

stage: commit review -> resolved
2014-09-06 19:52:08python-devsetnosy: + python-dev
messages: + msg226508
2014-09-06 18:07:14terry.reedysetmessages: + msg226500
stage: patch review -> commit review
2014-09-06 07:28:45serhiy.storchakasetfiles: + tkinter_splitdict_3.patch

messages: + msg226474
2014-09-05 19:34:47terry.reedysetmessages: + msg226447
2014-09-05 08:07:41serhiy.storchakasetmessages: + msg226406
2014-08-21 05:55:44serhiy.storchakasetfiles: + tkinter_splitdict_2.patch

messages: + msg225597
2014-08-20 23:39:41terry.reedysetmessages: + msg225594
2014-08-19 06:16:14serhiy.storchakacreate