Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 203eb31

Browse files
Issue #16809: Tkinter's splitlist() and split() methods now accept Tcl_Obj
argument. This is needed for support Tcl/Tk 8.6.
1 parent 1852b30 commit 203eb31

3 files changed

Lines changed: 60 additions & 12 deletions

File tree

Lib/test/test_tcl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def test_splitlist(self):
200200
(('a', 3.4), ('a', 3.4)),
201201
((), ()),
202202
(call('list', 1, '2', (3.4,)), (1, '2', (3.4,))),
203+
(call('dict', 'create', 1, '\u20ac', b'\xe2\x82\xac', (3.4,)),
204+
(1, '\u20ac', '\u20ac', (3.4,))),
203205
]
204206
for arg, res in testcases:
205207
self.assertEqual(splitlist(arg), res, msg=arg)
@@ -232,6 +234,8 @@ def test_split(self):
232234
(('a', (2, 3.4)), ('a', (2, 3.4))),
233235
((), ()),
234236
(call('list', 1, '2', (3.4,)), (1, '2', (3.4,))),
237+
(call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
238+
(12, '\u20ac', '\u20ac', (3.4,))),
235239
]
236240
for arg, res in testcases:
237241
self.assertEqual(split(arg), res, msg=arg)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ Core and Builtins
6666
Library
6767
-------
6868

69+
- Issue #16809: Tkinter's splitlist() and split() methods now accept Tcl_Obj
70+
argument.
71+
6972
- Issue #18324: set_payload now correctly handles binary input. This also
7073
supersedes the previous fixes for #14360, #1717, and #16564.
7174

Modules/_tkinter.c

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,16 +1940,35 @@ Tkapp_SplitList(PyObject *self, PyObject *args)
19401940
char *list;
19411941
int argc;
19421942
char **argv;
1943-
PyObject *v;
1943+
PyObject *arg, *v;
19441944
int i;
19451945

1946-
if (PyTuple_Size(args) == 1) {
1947-
v = PyTuple_GetItem(args, 0);
1948-
if (PyTuple_Check(v)) {
1949-
Py_INCREF(v);
1950-
return v;
1946+
if (!PyArg_ParseTuple(args, "O:splitlist", &arg))
1947+
return NULL;
1948+
if (PyTclObject_Check(arg)) {
1949+
int objc;
1950+
Tcl_Obj **objv;
1951+
if (Tcl_ListObjGetElements(Tkapp_Interp(self),
1952+
((PyTclObject*)arg)->value,
1953+
&objc, &objv) == TCL_ERROR) {
1954+
return Tkinter_Error(self);
1955+
}
1956+
if (!(v = PyTuple_New(objc)))
1957+
return NULL;
1958+
for (i = 0; i < objc; i++) {
1959+
PyObject *s = FromObj(self, objv[i]);
1960+
if (!s || PyTuple_SetItem(v, i, s)) {
1961+
Py_DECREF(v);
1962+
return NULL;
1963+
}
19511964
}
1965+
return v;
19521966
}
1967+
if (PyTuple_Check(arg)) {
1968+
Py_INCREF(arg);
1969+
return arg;
1970+
}
1971+
19531972
if (!PyArg_ParseTuple(args, "et:splitlist", "utf-8", &list))
19541973
return NULL;
19551974

@@ -1980,16 +1999,38 @@ Tkapp_SplitList(PyObject *self, PyObject *args)
19801999
static PyObject *
19812000
Tkapp_Split(PyObject *self, PyObject *args)
19822001
{
1983-
PyObject *v;
2002+
PyObject *arg, *v;
19842003
char *list;
19852004

1986-
if (PyTuple_Size(args) == 1) {
1987-
PyObject* o = PyTuple_GetItem(args, 0);
1988-
if (PyTuple_Check(o)) {
1989-
o = SplitObj(o);
1990-
return o;
2005+
if (!PyArg_ParseTuple(args, "O:split", &arg))
2006+
return NULL;
2007+
if (PyTclObject_Check(arg)) {
2008+
Tcl_Obj *value = ((PyTclObject*)arg)->value;
2009+
int objc;
2010+
Tcl_Obj **objv;
2011+
int i;
2012+
if (Tcl_ListObjGetElements(Tkapp_Interp(self), value,
2013+
&objc, &objv) == TCL_ERROR) {
2014+
return FromObj(self, value);
19912015
}
2016+
if (objc == 0)
2017+
return PyUnicode_FromString("");
2018+
if (objc == 1)
2019+
return FromObj(self, objv[0]);
2020+
if (!(v = PyTuple_New(objc)))
2021+
return NULL;
2022+
for (i = 0; i < objc; i++) {
2023+
PyObject *s = FromObj(self, objv[i]);
2024+
if (!s || PyTuple_SetItem(v, i, s)) {
2025+
Py_DECREF(v);
2026+
return NULL;
2027+
}
2028+
}
2029+
return v;
19922030
}
2031+
if (PyTuple_Check(arg))
2032+
return SplitObj(arg);
2033+
19932034
if (!PyArg_ParseTuple(args, "et:split", "utf-8", &list))
19942035
return NULL;
19952036
v = Split(list);

0 commit comments

Comments
 (0)