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

Skip to content

Commit 369606d

Browse files
Issue #19028: Fixed tkinter.Tkapp.merge() for non-string arguments.
1 parent 587b305 commit 369606d

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

Lib/test/test_tcl.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,37 @@ def test_split(self):
254254
for arg, res in testcases:
255255
self.assertEqual(split(arg), res, msg=arg)
256256

257+
def test_merge(self):
258+
with support.check_warnings(('merge is deprecated',
259+
DeprecationWarning)):
260+
merge = self.interp.tk.merge
261+
call = self.interp.tk.call
262+
testcases = [
263+
((), ''),
264+
(('a',), 'a'),
265+
((2,), '2'),
266+
(('',), '{}'),
267+
('{', '\\{'),
268+
(('a', 'b', 'c'), 'a b c'),
269+
((' ', '\t', '\r', '\n'), '{ } {\t} {\r} {\n}'),
270+
(('a', ' ', 'c'), 'a { } c'),
271+
(('a', '€'), 'a €'),
272+
(('a', '\U000104a2'), 'a \U000104a2'),
273+
(('a', b'\xe2\x82\xac'), 'a €'),
274+
(('a', ('b', 'c')), 'a {b c}'),
275+
(('a', 2), 'a 2'),
276+
(('a', 3.4), 'a 3.4'),
277+
(('a', (2, 3.4)), 'a {2 3.4}'),
278+
((), ''),
279+
((call('list', 1, '2', (3.4,)),), '{1 2 3.4}'),
280+
((call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),),
281+
'{12 € € 3.4}'),
282+
]
283+
for args, res in testcases:
284+
self.assertEqual(merge(*args), res, msg=args)
285+
self.assertRaises(UnicodeDecodeError, merge, b'\x80')
286+
self.assertRaises(UnicodeEncodeError, merge, '\udc80')
287+
257288

258289
class BigmemTclTest(unittest.TestCase):
259290

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Core and Builtins
6868
Library
6969
-------
7070

71+
- Issue #19028: Fixed tkinter.Tkapp.merge() for non-string arguments.
72+
7173
- Issue #3015: Fixed tkinter with wantobject=False. Any Tcl command call
7274
returned empty string.
7375

Modules/_tkinter.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,8 @@ AsString(PyObject *value, PyObject *tmp)
331331
{
332332
if (PyBytes_Check(value))
333333
return PyBytes_AsString(value);
334-
else if (PyUnicode_Check(value)) {
335-
PyObject *v = PyUnicode_AsUTF8String(value);
336-
if (v == NULL)
337-
return NULL;
338-
if (PyList_Append(tmp, v) != 0) {
339-
Py_DECREF(v);
340-
return NULL;
341-
}
342-
Py_DECREF(v);
343-
return PyBytes_AsString(v);
344-
}
334+
else if (PyUnicode_Check(value))
335+
return PyUnicode_AsUTF8(value);
345336
else {
346337
PyObject *v = PyObject_Str(value);
347338
if (v == NULL)
@@ -351,7 +342,7 @@ AsString(PyObject *value, PyObject *tmp)
351342
return NULL;
352343
}
353344
Py_DECREF(v);
354-
return PyBytes_AsString(v);
345+
return PyUnicode_AsUTF8(v);
355346
}
356347
}
357348

0 commit comments

Comments
 (0)