[Python-checkins] bpo-33096: Fix ttk.Treeview.insert. (GH-6228)
Miss Islington (bot)
webhook-mailer at python.org
Mon Mar 26 04:20:13 EDT 2018
https://github.com/python/cpython/commit/45116d393f713bbe918f16b33a0bba28b15bc96b
commit: 45116d393f713bbe918f16b33a0bba28b15bc96b
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-03-26T01:20:10-07:00
summary:
bpo-33096: Fix ttk.Treeview.insert. (GH-6228)
Allow ttk.Treeview.insert to insert iid that has a false boolean value.
Note iid=0 and iid=False would be same.
(cherry picked from commit 3ab44c0783eebdff687014f7d14d5dec59b6bd39)
Co-authored-by: Garvit Khatri <garvitdelhi at gmail.com>
files:
A Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst
M Lib/tkinter/test/test_ttk/test_widgets.py
M Lib/tkinter/ttk.py
diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py
index ab0db2878e13..cb991931853a 100644
--- a/Lib/tkinter/test/test_ttk/test_widgets.py
+++ b/Lib/tkinter/test/test_ttk/test_widgets.py
@@ -1485,6 +1485,15 @@ def test_insert_item(self):
self.tv.insert('', 'end', text=value), text=None),
value)
+ # test for values which are not None
+ itemid = self.tv.insert('', 'end', 0)
+ self.assertEqual(itemid, '0')
+ itemid = self.tv.insert('', 'end', 0.0)
+ self.assertEqual(itemid, '0.0')
+ # this is because False resolves to 0 and element with 0 iid is already present
+ self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end', False)
+ self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end', '')
+
def test_selection(self):
self.assertRaises(TypeError, self.tv.selection, 'spam')
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py
index 42e29bd3e5c8..3cf5faf10d7a 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -1336,7 +1336,7 @@ def insert(self, parent, index, iid=None, **kw):
already exist in the tree. Otherwise, a new unique identifier
is generated."""
opts = _format_optdict(kw)
- if iid:
+ if iid is not None:
res = self.tk.call(self._w, "insert", parent, index,
"-id", iid, *opts)
else:
diff --git a/Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst b/Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst
new file mode 100644
index 000000000000..c55ea20b337d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst
@@ -0,0 +1,4 @@
+Allow ttk.Treeview.insert to insert iid that has a false boolean value.
+Note iid=0 and iid=False would be same.
+Patch by Garvit Khatri.
+
More information about the Python-checkins
mailing list