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 625093 - dir() doesn't override the lazyness of modules
dir() doesn't override the lazyness of modules
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-23 07:56 UTC by Lucian
Modified: 2010-12-03 01:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
dir now works for g-i modules (1.24 KB, patch)
2010-10-27 22:43 UTC, deepankar.sharma
committed Details | Review

Description Lucian 2010-07-23 07:56:31 UTC
Using dir() on a module imported from gi.repository doesn't show any of the relevant attributes.
dir() on other objects from gi seems to work, but I'm not sure if attributes for those are lazy in the first place.

I'm using pygi 0.6.0.
Comment 1 deepankar.sharma 2010-10-27 22:43:01 UTC
Created attachment 173362 [details] [review]
dir now works for g-i modules

I have added __dir__ methods to IntrospectionModule and DynamicModule. If foo is a module then dir(foo) now gives meaningful member names. This also makes autocompletion work in ipython and other tools.
Comment 2 johnp 2010-10-28 15:49:20 UTC
Comment on attachment 173362 [details] [review]
dir now works for g-i modules

Great looks good.  Can you add a test to tests/test_gi.py which does a dir on the repository object and checks to see that GIMarshallingTests is returned in the list?  Do you have commit access?
Comment 3 johnp 2010-10-28 18:45:00 UTC
I'm going to add a test myself and commit this because it is useful however there are issues that should be addressed:

First the ones I can fix easily:

 * whitespace - please make sure there are no trailing whitespace in your patches.  I fixed the four places where I found them.
 * you must return a list, not a map from dir - I think map was also a list in 2.x but in 3.x you must explicitly call list().  Fixed it.

The one that needs to be looked at in depth:

import gi.repository
dir(gi.repository)

This still reports a lazy loaded list of modules.  If you import Gtk for instance it will show up in the list.  But if you don't, it will not.  I think in order to close this bug this should be addressed.  It is useful to be able to do dir(gi.repository) to find out what typelibs are installed on the system.
Comment 4 deepankar.sharma 2010-10-28 21:26:41 UTC
I do not have commit access. This is the first time I have submitted any code to gnome. 
Apart from that, if it is agreed upon that dir(gi.repository) should return the list of typelibs then I can look at adding that functionality. 
Also sorry about the whitespaces, I was not aware of that convention.
Comment 5 johnp 2010-10-28 21:50:04 UTC
I committed the patch with my own fixes and tests.  It would be great if you looked into it.  As far as I can tell it may not be possible currently since we use sys.meta_path to import (in gi/repository/__init__.py) and there is no way to override __dir__ for that.  We may need to reorganize.  Anyway, see what you can do as I feel this is a very useful feature to have.