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: deprecate the split() method
Type: Stage: resolved
Components: Tkinter Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: erlendaasland, serhiy.storchaka, zach.ware
Priority: normal Keywords: patch

Created on 2019-10-04 15:33 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16584 merged serhiy.storchaka, 2019-10-04 15:45
PR 28237 merged erlendaasland, 2021-09-08 11:27
PR 29082 merged zach.ware, 2021-10-20 02:59
Messages (4)
msg353948 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-04 15:33
The tkapp.split() method has weird behavior. It splits a string recursively, so the type of items and the depth of nesting depends on spaces in string values. For example:

>>> import tkinter
>>> root = tkinter.Tcl()
>>> root.tk.split('Hi')
'Hi'
>>> root.tk.split('Hello "Good bye"')
('Hello', ('Good', 'bye'))

It may work as you meant in some cases (if items at the same level either all have spaces or all do not have spaces), but return unexpected  result for untested cases. It is more robust to use the tkapp.splitlist() method, which split exactly one level and always returns a tuple of strings. It can be used recursively if you need nested lists.

>>> root.tk.splitlist('Hi')
('Hi',)
>>> root.tk.splitlist('Hello "Good bye"')
('Hello', 'Good bye')
>>> [root.tk.splitlist(x) for x in root.tk.splitlist('Hello "Good bye"')]
[('Hello',), ('Good', 'bye')]
msg354186 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-08 11:31
New changeset d05b000c6bcd39dba4f4b2656e45954802649562 by Serhiy Storchaka in branch 'master':
bpo-38371: Tkinter: deprecate the split() method. (GH-16584)
https://github.com/python/cpython/commit/d05b000c6bcd39dba4f4b2656e45954802649562
msg401422 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-08 20:02
New changeset f235dd0784b92824565c4a4e72adc70fa3eab68f by Erlend Egeberg Aasland in branch 'main':
bpo-38371: Remove deprecated `tkinter` split() method (GH-28237)
https://github.com/python/cpython/commit/f235dd0784b92824565c4a4e72adc70fa3eab68f
msg404391 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2021-10-20 03:34
New changeset 085ccb0f177988065dbe9ef4c5cda434560066bc by Zachary Ware in branch 'main':
bpo-38371: Remove remaining use of tk.split from bigmem tcl test (GH-29082)
https://github.com/python/cpython/commit/085ccb0f177988065dbe9ef4c5cda434560066bc
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82552
2021-10-20 03:34:31zach.waresetmessages: + msg404391
2021-10-20 02:59:59zach.waresetnosy: + zach.ware

pull_requests: + pull_request27350
2021-09-08 20:02:26serhiy.storchakasetmessages: + msg401422
2021-09-08 11:27:21erlendaaslandsetnosy: + erlendaasland

pull_requests: + pull_request26657
2019-10-08 11:37:58serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-10-08 11:31:44serhiy.storchakasetmessages: + msg354186
2019-10-04 15:45:22serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request16175
2019-10-04 15:33:41serhiy.storchakacreate