Skip to content

bpo-38371: Tkinter: deprecate the split() method. #16584

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ Deprecated
the module will restrict its seeds to :const:`None`, :class:`int`,
:class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray`.

* Deprecated the ``split()`` method of :class:`_tkinter.TkappType` in
favour of the ``splitlist()`` method which has more consistent and
predicable behavior.
(Contributed by Serhiy Storchaka in :issue:`38371`.)


Removed
=======
Expand Down
13 changes: 9 additions & 4 deletions Lib/test/test_tcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import sys
import os
import warnings
from test import support

# Skip this test if the _tkinter module wasn't built.
Expand Down Expand Up @@ -573,9 +574,12 @@ def test_splitlist(self):
def test_split(self):
split = self.interp.tk.split
call = self.interp.tk.call
self.assertRaises(TypeError, split)
self.assertRaises(TypeError, split, 'a', 'b')
self.assertRaises(TypeError, split, 2)
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'\bsplit\b.*\bsplitlist\b',
DeprecationWarning)
self.assertRaises(TypeError, split)
self.assertRaises(TypeError, split, 'a', 'b')
self.assertRaises(TypeError, split, 2)
testcases = [
('2', '2'),
('', ''),
Expand Down Expand Up @@ -617,7 +621,8 @@ def test_split(self):
expected),
]
for arg, res in testcases:
self.assertEqual(split(arg), res, msg=arg)
with self.assertWarns(DeprecationWarning):
self.assertEqual(split(arg), res, msg=arg)

def test_splitdict(self):
splitdict = tkinter._splitdict
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Deprecated the ``split()`` method in :class:`_tkinter.TkappType` in favour
of the ``splitlist()`` method which has more consistent and predicable
behavior.
6 changes: 6 additions & 0 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,12 @@ _tkinter_tkapp_split(TkappObject *self, PyObject *arg)
PyObject *v;
char *list;

if (PyErr_WarnEx(PyExc_DeprecationWarning,
"split() is deprecated; consider using splitlist() instead", 1))
{
return NULL;
}

if (PyTclObject_Check(arg)) {
Tcl_Obj *value = ((PyTclObject*)arg)->value;
int objc;
Expand Down