Skip to content

Commit

Permalink
bpo-33096: Fix ttk.Treeview.insert. (pythonGH-6228)
Browse files Browse the repository at this point in the history
Allow ttk.Treeview.insert to insert iid that has a false boolean value.
Note iid=0 and iid=False would be same.
  • Loading branch information
plusminushalf authored and serhiy-storchaka committed Mar 26, 2018
1 parent 2b75fc2 commit 3ab44c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Lib/tkinter/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 3ab44c0

Please sign in to comment.