Skip to content

Commit f235dd0

Browse files
author
Erlend Egeberg Aasland
authored
bpo-38371: Remove deprecated tkinter split() method (GH-28237)
1 parent 84ca5fc commit f235dd0

File tree

5 files changed

+6
-264
lines changed

5 files changed

+6
-264
lines changed

Doc/whatsnew/3.11.rst

+3
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ Removed
328328
generator-based coroutine objects in the debug mode.
329329
(Contributed by Illia Volochii in :issue:`43216`.)
330330

331+
* Remove the deprecated ``split()`` method of :class:`_tkinter.TkappType`.
332+
(Contributed by Erlend E. Aasland in :issue:`38371`.)
333+
331334
Porting to Python 3.11
332335
======================
333336

Lib/test/test_tcl.py

-53
Original file line numberDiff line numberDiff line change
@@ -617,59 +617,6 @@ def test_splitlist(self):
617617
'arg=%a, %s' % (arg, dbg_info))
618618
self.assertRaises(TclError, splitlist, '{')
619619

620-
def test_split(self):
621-
split = self.interp.tk.split
622-
call = self.interp.tk.call
623-
with warnings.catch_warnings():
624-
warnings.filterwarnings('ignore', r'\bsplit\b.*\bsplitlist\b',
625-
DeprecationWarning)
626-
self.assertRaises(TypeError, split)
627-
self.assertRaises(TypeError, split, 'a', 'b')
628-
self.assertRaises(TypeError, split, 2)
629-
testcases = [
630-
('2', '2'),
631-
('', ''),
632-
('{}', ''),
633-
('""', ''),
634-
('{', '{'),
635-
('a\n b\t\r c\n ', ('a', 'b', 'c')),
636-
(b'a\n b\t\r c\n ', ('a', 'b', 'c')),
637-
('a \u20ac', ('a', '\u20ac')),
638-
(b'a \xe2\x82\xac', ('a', '\u20ac')),
639-
(b'a\xc0\x80b', 'a\x00b'),
640-
(b'a\xc0\x80b c\xc0\x80d', ('a\x00b', 'c\x00d')),
641-
(b'{a\xc0\x80b c\xc0\x80d', '{a\x00b c\x00d'),
642-
('a {b c}', ('a', ('b', 'c'))),
643-
(r'a b\ c', ('a', ('b', 'c'))),
644-
(('a', b'b c'), ('a', ('b', 'c'))),
645-
(('a', 'b c'), ('a', ('b', 'c'))),
646-
('a 2', ('a', '2')),
647-
(('a', 2), ('a', 2)),
648-
('a 3.4', ('a', '3.4')),
649-
(('a', 3.4), ('a', 3.4)),
650-
(('a', (2, 3.4)), ('a', (2, 3.4))),
651-
((), ()),
652-
([], ()),
653-
(['a', 'b c'], ('a', ('b', 'c'))),
654-
(['a', ['b', 'c']], ('a', ('b', 'c'))),
655-
(call('list', 1, '2', (3.4,)),
656-
(1, '2', (3.4,)) if self.wantobjects else
657-
('1', '2', '3.4')),
658-
]
659-
if tcl_version >= (8, 5):
660-
if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
661-
# Before 8.5.5 dicts were converted to lists through string
662-
expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
663-
else:
664-
expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
665-
testcases += [
666-
(call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
667-
expected),
668-
]
669-
for arg, res in testcases:
670-
with self.assertWarns(DeprecationWarning):
671-
self.assertEqual(split(arg), res, msg=arg)
672-
673620
def test_splitdict(self):
674621
splitdict = tkinter._splitdict
675622
tcl = self.interp.tk
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove the deprecated ``split()`` method of :class:`_tkinter.TkappType`.
2+
Patch by Erlend E. Aasland.

Modules/_tkinter.c

-202
Original file line numberDiff line numberDiff line change
@@ -506,145 +506,6 @@ unicodeFromTclObj(Tcl_Obj *value)
506506
#endif
507507
}
508508

509-
510-
static PyObject *
511-
Split(const char *list)
512-
{
513-
int argc;
514-
const char **argv;
515-
PyObject *v;
516-
517-
if (list == NULL) {
518-
Py_RETURN_NONE;
519-
}
520-
521-
if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
522-
/* Not a list.
523-
* Could be a quoted string containing funnies, e.g. {"}.
524-
* Return the string itself.
525-
*/
526-
return unicodeFromTclString(list);
527-
}
528-
529-
if (argc == 0)
530-
v = PyUnicode_FromString("");
531-
else if (argc == 1)
532-
v = unicodeFromTclString(argv[0]);
533-
else if ((v = PyTuple_New(argc)) != NULL) {
534-
int i;
535-
PyObject *w;
536-
537-
for (i = 0; i < argc; i++) {
538-
if ((w = Split(argv[i])) == NULL) {
539-
Py_DECREF(v);
540-
v = NULL;
541-
break;
542-
}
543-
PyTuple_SET_ITEM(v, i, w);
544-
}
545-
}
546-
Tcl_Free(FREECAST argv);
547-
return v;
548-
}
549-
550-
/* In some cases, Tcl will still return strings that are supposed to
551-
be lists. SplitObj walks through a nested tuple, finding string
552-
objects that need to be split. */
553-
554-
static PyObject *
555-
SplitObj(PyObject *arg)
556-
{
557-
if (PyTuple_Check(arg)) {
558-
Py_ssize_t i, size;
559-
PyObject *elem, *newelem, *result;
560-
561-
size = PyTuple_GET_SIZE(arg);
562-
result = NULL;
563-
/* Recursively invoke SplitObj for all tuple items.
564-
If this does not return a new object, no action is
565-
needed. */
566-
for(i = 0; i < size; i++) {
567-
elem = PyTuple_GET_ITEM(arg, i);
568-
newelem = SplitObj(elem);
569-
if (!newelem) {
570-
Py_XDECREF(result);
571-
return NULL;
572-
}
573-
if (!result) {
574-
Py_ssize_t k;
575-
if (newelem == elem) {
576-
Py_DECREF(newelem);
577-
continue;
578-
}
579-
result = PyTuple_New(size);
580-
if (!result)
581-
return NULL;
582-
for(k = 0; k < i; k++) {
583-
elem = PyTuple_GET_ITEM(arg, k);
584-
Py_INCREF(elem);
585-
PyTuple_SET_ITEM(result, k, elem);
586-
}
587-
}
588-
PyTuple_SET_ITEM(result, i, newelem);
589-
}
590-
if (result)
591-
return result;
592-
/* Fall through, returning arg. */
593-
}
594-
else if (PyList_Check(arg)) {
595-
Py_ssize_t i, size;
596-
PyObject *elem, *newelem, *result;
597-
598-
size = PyList_GET_SIZE(arg);
599-
result = PyTuple_New(size);
600-
if (!result)
601-
return NULL;
602-
/* Recursively invoke SplitObj for all list items. */
603-
for(i = 0; i < size; i++) {
604-
elem = PyList_GET_ITEM(arg, i);
605-
newelem = SplitObj(elem);
606-
if (!newelem) {
607-
Py_XDECREF(result);
608-
return NULL;
609-
}
610-
PyTuple_SET_ITEM(result, i, newelem);
611-
}
612-
return result;
613-
}
614-
else if (PyUnicode_Check(arg)) {
615-
int argc;
616-
const char **argv;
617-
const char *list = PyUnicode_AsUTF8(arg);
618-
619-
if (list == NULL ||
620-
Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
621-
Py_INCREF(arg);
622-
return arg;
623-
}
624-
Tcl_Free(FREECAST argv);
625-
if (argc > 1)
626-
return Split(list);
627-
/* Fall through, returning arg. */
628-
}
629-
else if (PyBytes_Check(arg)) {
630-
int argc;
631-
const char **argv;
632-
const char *list = PyBytes_AS_STRING(arg);
633-
634-
if (Tcl_SplitList((Tcl_Interp *)NULL, (char *)list, &argc, &argv) != TCL_OK) {
635-
Py_INCREF(arg);
636-
return arg;
637-
}
638-
Tcl_Free(FREECAST argv);
639-
if (argc > 1)
640-
return Split(PyBytes_AS_STRING(arg));
641-
/* Fall through, returning arg. */
642-
}
643-
Py_INCREF(arg);
644-
return arg;
645-
}
646-
647-
648509
/*[clinic input]
649510
module _tkinter
650511
class _tkinter.tkapp "TkappObject *" "&Tkapp_Type_spec"
@@ -2342,68 +2203,6 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
23422203
return v;
23432204
}
23442205

2345-
/*[clinic input]
2346-
_tkinter.tkapp.split
2347-
2348-
arg: object
2349-
/
2350-
2351-
[clinic start generated code]*/
2352-
2353-
static PyObject *
2354-
_tkinter_tkapp_split(TkappObject *self, PyObject *arg)
2355-
/*[clinic end generated code: output=e08ad832363facfd input=a1c78349eacaa140]*/
2356-
{
2357-
PyObject *v;
2358-
char *list;
2359-
2360-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2361-
"split() is deprecated; consider using splitlist() instead", 1))
2362-
{
2363-
return NULL;
2364-
}
2365-
2366-
if (PyTclObject_Check(arg)) {
2367-
Tcl_Obj *value = ((PyTclObject*)arg)->value;
2368-
int objc;
2369-
Tcl_Obj **objv;
2370-
int i;
2371-
if (Tcl_ListObjGetElements(Tkapp_Interp(self), value,
2372-
&objc, &objv) == TCL_ERROR) {
2373-
return FromObj(self, value);
2374-
}
2375-
if (objc == 0)
2376-
return PyUnicode_FromString("");
2377-
if (objc == 1)
2378-
return FromObj(self, objv[0]);
2379-
if (!(v = PyTuple_New(objc)))
2380-
return NULL;
2381-
for (i = 0; i < objc; i++) {
2382-
PyObject *s = FromObj(self, objv[i]);
2383-
if (!s) {
2384-
Py_DECREF(v);
2385-
return NULL;
2386-
}
2387-
PyTuple_SET_ITEM(v, i, s);
2388-
}
2389-
return v;
2390-
}
2391-
if (PyTuple_Check(arg) || PyList_Check(arg))
2392-
return SplitObj(arg);
2393-
2394-
if (!PyArg_Parse(arg, "et:split", "utf-8", &list))
2395-
return NULL;
2396-
if (strlen(list) >= INT_MAX) {
2397-
PyErr_SetString(PyExc_OverflowError, "string is too long");
2398-
PyMem_Free(list);
2399-
return NULL;
2400-
}
2401-
v = Split(list);
2402-
PyMem_Free(list);
2403-
return v;
2404-
}
2405-
2406-
24072206

24082207
/** Tcl Command **/
24092208

@@ -3331,7 +3130,6 @@ static PyMethodDef Tkapp_methods[] =
33313130
_TKINTER_TKAPP_EXPRDOUBLE_METHODDEF
33323131
_TKINTER_TKAPP_EXPRBOOLEAN_METHODDEF
33333132
_TKINTER_TKAPP_SPLITLIST_METHODDEF
3334-
_TKINTER_TKAPP_SPLIT_METHODDEF
33353133
_TKINTER_TKAPP_CREATECOMMAND_METHODDEF
33363134
_TKINTER_TKAPP_DELETECOMMAND_METHODDEF
33373135
_TKINTER_TKAPP_CREATEFILEHANDLER_METHODDEF

Modules/clinic/_tkinter.c.h

+1-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)