[Python-checkins] bpo-38371: Tkinter: deprecate the split() method. (GH-16584)

Serhiy Storchaka webhook-mailer at python.org
Tue Oct 8 07:31:45 EDT 2019


https://github.com/python/cpython/commit/d05b000c6bcd39dba4f4b2656e45954802649562
commit: d05b000c6bcd39dba4f4b2656e45954802649562
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-10-08T14:31:35+03:00
summary:

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

files:
A Misc/NEWS.d/next/Library/2019-10-04-18-39-59.bpo-38371.S6Klvm.rst
M Doc/whatsnew/3.9.rst
M Lib/test/test_tcl.py
M Modules/_tkinter.c

diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 9f2a659a9dca7..6b4abc0567c30 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -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
 =======
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index 3183ea850f73b..1c5b9cf2bd2a8 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -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.
@@ -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'),
             ('', ''),
@@ -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
diff --git a/Misc/NEWS.d/next/Library/2019-10-04-18-39-59.bpo-38371.S6Klvm.rst b/Misc/NEWS.d/next/Library/2019-10-04-18-39-59.bpo-38371.S6Klvm.rst
new file mode 100644
index 0000000000000..583399531acd1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-10-04-18-39-59.bpo-38371.S6Klvm.rst
@@ -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.
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index c431d611d4d0c..235cb6bc28dd5 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -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;



More information about the Python-checkins mailing list