GNOME Bugzilla – Bug 625093
dir() doesn't override the lazyness of modules
Last modified: 2010-12-03 01:50:14 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.
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 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?
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.
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.
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.