GNOME Bugzilla – Bug 770665
It is not possible to instantiate a TreePath empty
Last modified: 2018-01-10 20:55:53 UTC
Created attachment 334547 [details] [review] patch The __new__ method of TreePath has zero as default value for path. So this makes it point to the first row. But indeed it could be needed to instantiate a TreePath empty. For example, it is needed to call rows_reordered which must reorder the all tree. Here is a patch that allow to use None, () and '' as path. Also I put None as default value for path because it seems more logical but if it is needed for backward compatibility, we can keep 0 as default value. FYI, it is possible to get a empty TreePath with this code: path = Gtk.TreePath() path.up()
I'm afraid that this change would break existing code. What about using Gtk.TreePath.new() ?
As I said if we keep default value to 0 then it will break any existing code because None, () and '' are currently failing values. But default value of None is closer to what the C code does and I think is more logical.
I don't see how not changing anything will break existing code. Making it accept empty strings and empty sequences sounds OK to me, as we already accept lists and sequences there. Please include tests for your changes.
Created attachment 334662 [details] [review] patch with test Here is with test (but I could not test it as I can not find gnome-autogen.sh on OpenBSD).
Review of attachment 334662 [details] [review]: ::: tests/test_overrides_gtk.py @@ +1343,3 @@ self.assertFalse(p1 <= None) + p1 = Gtk.TreePath(None) Looks like this would clobber p1 which has a different expectation later on. Can you add these as a new "test_empty()" test method?
Created attachment 342409 [details] [review] patch with separate test Here is a new version of the patch with a separate test.
Review of attachment 342409 [details] [review]: Tests are failing with the patch applied. test_tree_path_empty (test_overrides_gtk.TestTreeModel) ... (runtests.py:8994): Gtk-CRITICAL **: gtk_tree_path_compare: assertion 'a->depth > 0' failed test_tree_model (test_overrides_gtk.TestTreeModel) ... (runtests.py:9094): Gtk-CRITICAL **: gtk_tree_model_get_iter: assertion 'path->depth > 0' failed
Created attachment 354416 [details] [review] patch with fixed tests I could run the tests now, so here is a new version for which the tests pass. I decided to raise TypeError when coercing path on TreeModel because empty path can not be used for TreeModel. Also as to_string may return None, I change it to return empty string.
I forgot to say that I removed the comparison between empty TreePath because Gtk object does not support it.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/121.