[Python-checkins] bpo-33096: Fix ttk.Treeview.insert. (GH-6228)

Serhiy Storchaka webhook-mailer at python.org
Mon Mar 26 03:02:09 EDT 2018


https://github.com/python/cpython/commit/3ab44c0783eebdff687014f7d14d5dec59b6bd39
commit: 3ab44c0783eebdff687014f7d14d5dec59b6bd39
branch: master
author: Garvit Khatri <garvitdelhi at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-03-26T10:02:05+03: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.

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 bbc508d35810..5b0e29cdccaf 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 490b502a65f1..573544dd84a3 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -1361,7 +1361,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