[Python-checkins] bpo-33096: Fix ttk.Treeview.insert. (GH-6228)
Miss Islington (bot)
webhook-mailer at python.org
Mon Mar 26 04:19:55 EDT 2018
https://github.com/python/cpython/commit/a7b1b847f665aafc22557917cea32ec34c9b4418
commit: a7b1b847f665aafc22557917cea32ec34c9b4418
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-03-26T01:19:52-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 5325e36b5212..06e3dfe70d5d 100644
--- a/Lib/tkinter/test/test_ttk/test_widgets.py
+++ b/Lib/tkinter/test/test_ttk/test_widgets.py
@@ -1662,6 +1662,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 c1651159b703..12f4ac0bd908 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -1363,7 +1363,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