Skip to content

Commit d05b000

Browse files
bpo-38371: Tkinter: deprecate the split() method. (GH-16584)
1 parent d7c3873 commit d05b000

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Doc/whatsnew/3.9.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ Deprecated
191191
the module will restrict its seeds to :const:`None`, :class:`int`,
192192
:class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray`.
193193

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

195200
Removed
196201
=======

Lib/test/test_tcl.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import sys
55
import os
6+
import warnings
67
from test import support
78

89
# Skip this test if the _tkinter module wasn't built.
@@ -573,9 +574,12 @@ def test_splitlist(self):
573574
def test_split(self):
574575
split = self.interp.tk.split
575576
call = self.interp.tk.call
576-
self.assertRaises(TypeError, split)
577-
self.assertRaises(TypeError, split, 'a', 'b')
578-
self.assertRaises(TypeError, split, 2)
577+
with warnings.catch_warnings():
578+
warnings.filterwarnings('ignore', r'\bsplit\b.*\bsplitlist\b',
579+
DeprecationWarning)
580+
self.assertRaises(TypeError, split)
581+
self.assertRaises(TypeError, split, 'a', 'b')
582+
self.assertRaises(TypeError, split, 2)
579583
testcases = [
580584
('2', '2'),
581585
('', ''),
@@ -617,7 +621,8 @@ def test_split(self):
617621
expected),
618622
]
619623
for arg, res in testcases:
620-
self.assertEqual(split(arg), res, msg=arg)
624+
with self.assertWarns(DeprecationWarning):
625+
self.assertEqual(split(arg), res, msg=arg)
621626

622627
def test_splitdict(self):
623628
splitdict = tkinter._splitdict
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecated the ``split()`` method in :class:`_tkinter.TkappType` in favour
2+
of the ``splitlist()`` method which has more consistent and predicable
3+
behavior.

Modules/_tkinter.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,12 @@ _tkinter_tkapp_split(TkappObject *self, PyObject *arg)
23042304
PyObject *v;
23052305
char *list;
23062306

2307+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2308+
"split() is deprecated; consider using splitlist() instead", 1))
2309+
{
2310+
return NULL;
2311+
}
2312+
23072313
if (PyTclObject_Check(arg)) {
23082314
Tcl_Obj *value = ((PyTclObject*)arg)->value;
23092315
int objc;

0 commit comments

Comments
 (0)