]> granicus.if.org Git - python/commitdiff
bpo-33096: Fix ttk.Treeview.insert. (GH-6228)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 26 Mar 2018 08:19:52 +0000 (01:19 -0700)
committerGitHub <noreply@github.com>
Mon, 26 Mar 2018 08:19:52 +0000 (01:19 -0700)
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@gmail.com>
Lib/tkinter/test/test_ttk/test_widgets.py
Lib/tkinter/ttk.py
Misc/NEWS.d/next/Library/2018-03-25-13-18-16.bpo-33096.ofdbe7.rst [new file with mode: 0644]

index 5325e36b5212b516f868be41f6bea9e7629f4527..06e3dfe70d5dc37d0f39929d729bc3622bbaa5cb 100644 (file)
@@ -1662,6 +1662,15 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
             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')
index c1651159b7030d2900c7e4e0df4a24aad3147b2e..12f4ac0bd9086bbc54507fedc3683836a0d8f786 100644 (file)
@@ -1363,7 +1363,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
         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 (file)
index 0000000..c55ea20
--- /dev/null
@@ -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.
+