GNOME Bugzilla – Bug 639232
Imported modules do not show which typelib file they are using.
Last modified: 2011-01-12 13:21:20 UTC
Normal modules in python have a meaningful repr() string which includes the path of the module's file. For example: >>> import os >>> repr(os) "<module 'os' from '/usr/lib/python2.6/os.pyc'>" Modules imported from gi.repository should include the path of the typelib file in the repr() string so that developers can see what file was used to dynamically generate the module.
Created attachment 178067 [details] [review] Add a __repr__() method to DynamicModule. This patch adds a __repr__() method to DynamicModule so that modules provide a meaningful string with the typelib path included: >>> from gi.repository import Gtk >>> Gtk <gi.module.DynamicModule 'Gtk' from '/home/laszlo/Dev/gnome-jh-install/lib64/girepository-1.0/Gtk-3.0.typelib'>
Created attachment 178074 [details] [review] Add a __repr__() method to DynamicModule. This patch adds a __repr__() method to DynamicModule so that modules provide a meaningful string with the typelib path included: >>> from gi.repository import Gtk >>> Gtk <gi.module.DynamicModule 'Gtk' from '/home/laszlo/Dev/gnome-jh-install/lib64/girepository-1.0/Gtk-3.0.typelib'>
Thanks! Attachment 178074 [details] pushed as 4992dca - Add a __repr__() method to DynamicModule.
I don't think this patch was good enough to be committed. Instead of calling repository.require directly and later repository.get_typelib_path, __repr__ should call _import as in __getattr__, and use the __path__ that is set. A similar comment applies to __dir__ as well but that is out of the scope of this bug.
(In reply to comment #4) > I don't think this patch was good enough to be committed. Instead of calling > repository.require directly and later repository.get_typelib_path, __repr__ > should call _import as in __getattr__, and use the __path__ that is set. And why is that better?
(In reply to comment #5) > (In reply to comment #4) > > I don't think this patch was good enough to be committed. Instead of calling > > repository.require directly and later repository.get_typelib_path, __repr__ > > should call _import as in __getattr__, and use the __path__ that is set. > > And why is that better? Because it reuses code that is already there instead of duplicating it.
(In reply to comment #6) > (In reply to comment #5) > > (In reply to comment #4) > > > I don't think this patch was good enough to be committed. Instead of calling > > > repository.require directly and later repository.get_typelib_path, __repr__ > > > should call _import as in __getattr__, and use the __path__ that is set. > > > > And why is that better? > > Because it reuses code that is already there instead of duplicating it. We want to ensure that the typelib is loaded, not do the whole import dance. I don't think discussing this choice is a good use of maintainer time, and also that we should have accepted any of the two options, at the submitter discretion.