]> 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:20:10 +0000 (01:20 -0700)
committerGitHub <noreply@github.com>
Mon, 26 Mar 2018 08:20:10 +0000 (01:20 -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 ab0db2878e13df4dcf000c3635eef2ffdd107207..cb991931853a09f73d888b5b4f4df31f1c2225fc 100644 (file)
@@ -1485,6 +1485,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 42e29bd3e5c85fadba989ff44e74538de6ec72a0..3cf5faf10d7a683fe57fa5120e55698cdec0a31a 100644 (file)
@@ -1336,7 +1336,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.
+