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 660018 - [pygi] GtkTreeIter inconsistency
[pygi] GtkTreeIter inconsistency
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Martin Pitt
Python bindings maintainers
: 674968 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-09-24 16:20 UTC by Sandro Mani
Modified: 2012-04-28 14:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test case (488 bytes, text/x-python)
2011-09-24 16:20 UTC, Sandro Mani
  Details
Add missing override for TreeModel.iter_previous() (1.95 KB, patch)
2012-04-23 13:25 UTC, Martin Pitt
none Details | Review

Description Sandro Mani 2011-09-24 16:20:18 UTC
Created attachment 197406 [details]
test case

According to
http://developer.gnome.org/gtk3/unstable/GtkTreeModel.html#gtk-tree-model-iter-next
one would expect

status = model.iter_next(it)
to work to increase it, with status indicating whether it succeeded, but one needs to write
it = model.it_next(it); status = it and model.iter_is_valid(it)

On the other hand,
status = model.iter_previous(it)
works as documented.

Testcase attached.

Happens with gtk3-3.0.12-1.fc15.x86_64 and gtk3-3.1.92-1.fc16.x86_64.
Comment 1 Kristian Rietveld 2011-09-24 17:03:07 UTC
This should work just fine in C.  Reassigning to PyGObject for investigation.
Comment 2 Timo Vanwynsberghe 2011-09-24 18:12:37 UTC
Looking at the overrides, I can see this method for the TreeModel:
    def iter_next(self, aiter):
        next_iter = aiter.copy()
        success = super(TreeModel, self).iter_next(next_iter)
        if success:
            return next_iter

But not for iter_previous(). This explains why you get an iter from the one and the status for the other.
Removing this method would break some other things in the overrides, like the get_next() method for TreeModelRow and TreeModelRowIter.

I'm not a PyGobject developer, so can't comment on the best way to solve this though.
Comment 3 johnp 2011-10-14 22:14:02 UTC
iter_previous should be fix to work like iter_next and iter_next should return None if the iter is invalid so this would work:

iter = model.iter_first()
while iter:
    # do something with iter
    iter = model.iter_next(iter)

if you needed to keep the invalid iter around this should work though I have never tested it:

iter = model.iter_first()
result = iter
while result:
    # do something with iter
    result = model.iter_next(iter)

technically passing the scope of the function without returning anything will always result in None being returned but we could be more explicit here for readers of the code.
Comment 4 Martin Pitt 2012-04-23 13:25:00 UTC
Still an issue with pygobject 3.2.
Comment 5 Martin Pitt 2012-04-23 13:25:47 UTC
Created attachment 212603 [details] [review]
Add missing override for TreeModel.iter_previous()
Comment 7 Martin Pitt 2012-04-28 14:27:31 UTC
*** Bug 674968 has been marked as a duplicate of this bug. ***