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 623278 - Make GFileEnumerator iteratable
Make GFileEnumerator iteratable
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 634636 (view as bug list)
Depends on: 638899
Blocks:
 
 
Reported: 2010-07-01 10:17 UTC by Ignacio Casal Quinteiro (nacho)
Modified: 2011-01-19 14:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
file enumerator v1 (3.06 KB, patch)
2010-07-07 17:15 UTC, Ignacio Casal Quinteiro (nacho)
needs-work Details | Review
Testing iterability of a GFileEnumerator in a standalone script (716 bytes, text/plain)
2010-12-05 12:07 UTC, Holger Berndt
  Details
Patch to override GFileEnumerator behavior. (2.27 KB, patch)
2010-12-16 23:46 UTC, Tony Young
none Details | Review
Revised patch. (3.48 KB, patch)
2010-12-18 20:31 UTC, Tony Young
none Details | Review
Amended patch. (3.47 KB, patch)
2010-12-18 21:55 UTC, Tony Young
none Details | Review
file enumerator v2 (3.46 KB, patch)
2010-12-20 12:34 UTC, Ignacio Casal Quinteiro (nacho)
committed Details | Review

Description Ignacio Casal Quinteiro (nacho) 2010-07-01 10:17:58 UTC
We should override that class to make it iteratable so it is easier to use.
Comment 1 Ignacio Casal Quinteiro (nacho) 2010-07-07 17:15:31 UTC
Created attachment 165430 [details] [review]
file enumerator v1

Far from finished. I can't really make a good test and finish it as I get an error:

Traceback (most recent call last):
  • File "./runtests.py", line 32 in <module>
    suite.addTest(loader.loadTestsFromName(name))
  • File "/usr/lib/python2.6/unittest.py", line 576 in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  • File "../tests/test_overrides.py", line 15 in <module>
    from gi.repository import Gio
  • File "../gi/importer.py", line 71 in load_module
    overrides_modules = __import__('gi.overrides', fromlist=[namespace])
  • File "../gi/overrides/Gio.py", line 43 in <module>
    FileEnumerator = override(FileEnumerator)
  • File "../gi/types.py", line 163 in override
    g_type = type_.__info__.get_g_type()
AttributeError: type object 'FileEnumerator' has no attribute '__info__'

Comment 2 Paolo Borelli 2010-11-21 20:06:13 UTC
*** Bug 634636 has been marked as a duplicate of this bug. ***
Comment 3 Holger Berndt 2010-12-05 12:07:35 UTC
Created attachment 175867 [details]
Testing iterability of a GFileEnumerator in a standalone script

I'm a little confused at what the situation of this enhancement request is.

If I try to iterate a GFileEnumerator as in the attached script, I get a "TypeError: '__main__.GLocalFileEnumerator' object is not iterable". However, if I turn the very same code into a unit test for the overrides test suite, it runs smoothly. I have no idea what the test suite does differently.
Comment 4 Ignacio Casal Quinteiro (nacho) 2010-12-05 21:17:56 UTC
We want it to be iterable so we can do things like:

for info in enumerator:
   print info.get_name()
Comment 5 Tony Young 2010-12-16 23:46:14 UTC
Created attachment 176567 [details] [review]
Patch to override GFileEnumerator behavior.

As part of a Google Code-in task (see: http://www.google-melange.com/gci/task/show/google/gci2010/gnome/t129121625299), I've amended the patch (with help from the people at #python@irc.gnome.org, pbor and J5 in particular) to work correctly.

This patch was written for commit b03cc9e0d66d8caea3cd6a63db198c43de9267e9.

Tell me if you run into any problems with it.
Comment 6 Paolo Borelli 2010-12-17 09:04:51 UTC
Hi Tony, thanks for working on this.

For every override we also add unit tests to test_overrides.py. The original patch by nachio had a first test. Can you please add tests?
Comment 7 Tony Young 2010-12-18 20:31:19 UTC
Created attachment 176678 [details] [review]
Revised patch.

Here's a revised version of the patch which adds a new test case that compares the output of iterating through a FileEnumerator with FileEnumerator.next_file behavior.
Comment 8 Paolo Borelli 2010-12-18 21:34:03 UTC
Review of attachment 176678 [details] [review]:

Patch looks good to me except I'd call the unit test function just "test_file_enumerator" for consistency with the other tests.
Comment 9 Tony Young 2010-12-18 21:55:55 UTC
Created attachment 176687 [details] [review]
Amended patch.

Final revision of the patch which names the test test_file_enumerator.
Comment 10 Ignacio Casal Quinteiro (nacho) 2010-12-18 22:06:02 UTC
Btw pbor, should we also need to add?:

def __bool__(self):
        return True

    # alias for Python 2.x object protocol
    __nonzero__ = __bool__
Comment 11 Paolo Borelli 2010-12-19 00:46:00 UTC
No, I do not think we should override bool, in this case it makes sense that if the list is empty the enumerator is false.
Comment 12 Ignacio Casal Quinteiro (nacho) 2010-12-20 12:34:12 UTC
Created attachment 176759 [details] [review]
file enumerator v2

Fixed some minor issues. Can somebody test it? Here the test doesn't pass due to not finding the override. Do I need to add the Gio module somewhere else to be detected?
Comment 13 johnp 2010-12-20 18:56:39 UTC
Comment on attachment 176759 [details] [review]
file enumerator v2

looks good
Comment 14 Holger Berndt 2011-01-04 15:44:12 UTC
Patch works fine for me.
Comment 15 Holger Berndt 2011-01-04 15:59:22 UTC
Just to clarify: With this patch applied, I can iterate over GFileEnumerators in a project using pygobject. However, the corresponding test in "make check" fails for me too.
Comment 16 Tomeu Vizoso 2011-01-07 11:12:40 UTC
Tests pass once we remove the gio tests.
Comment 17 Ignacio Casal Quinteiro (nacho) 2011-01-19 14:00:41 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.