After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 770665 - It is not possible to instantiate a TreePath empty
It is not possible to instantiate a TreePath empty
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other OpenBSD
: Normal major
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2016-08-31 17:31 UTC by Cédric Krier
Modified: 2018-01-10 20:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (544 bytes, patch)
2016-08-31 17:31 UTC, Cédric Krier
none Details | Review
patch with test (1.11 KB, patch)
2016-09-02 16:38 UTC, Cédric Krier
none Details | Review
patch with separate test (1.13 KB, patch)
2016-12-23 09:33 UTC, Cédric Krier
none Details | Review
patch with fixed tests (1.89 KB, patch)
2017-06-25 11:29 UTC, Cédric Krier
none Details | Review

Description Cédric Krier 2016-08-31 17:31:37 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()
Comment 1 Christoph Reiter (lazka) 2016-08-31 17:41:54 UTC
I'm afraid that this change would break existing code.

What about using Gtk.TreePath.new() ?
Comment 2 Cédric Krier 2016-08-31 20:18:26 UTC
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.
Comment 3 Christoph Reiter (lazka) 2016-09-02 15:49:46 UTC
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.
Comment 4 Cédric Krier 2016-09-02 16:38:41 UTC
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).
Comment 5 Simon Feltman 2016-12-23 03:31:40 UTC
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?
Comment 6 Cédric Krier 2016-12-23 09:33:23 UTC
Created attachment 342409 [details] [review]
patch with separate test

Here is a new version of the patch with a separate test.
Comment 7 Christoph Reiter (lazka) 2017-03-26 14:57:39 UTC
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
Comment 8 Cédric Krier 2017-06-25 11:29:20 UTC
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.
Comment 9 Cédric Krier 2017-06-25 11:30:33 UTC
I forgot to say that I removed the comparison between empty TreePath because Gtk object does not support it.
Comment 10 GNOME Infrastructure Team 2018-01-10 20:55:53 UTC
-- 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.