GNOME Bugzilla – Bug 687697
Errors when importing a non-existing module are too verbose
Last modified: 2014-03-22 19:47:52 UTC
This will give both a logged error and raise and ImportError. >>> from gi.repository import NonExistingModule ERROR:root:Could not find any typelib for NonExistingModule ImportError: cannot import name NonExistingModule The python importer protocol specifies to return None from "find_module" when something is not found. Python will then raise the appropriate exception for us making the logging message unnecessary. This should be removed from gi/importer.py
On second thought, the logging might be somewhat useful as it could hint at potential problems in the gi repository itself. In this case we could change it to logging.debug instead of error as this does not show up by default.
PEP 302 suggests that find_module can raise an error that will be propagated upwards. Perhaps find_module should raise an ImportError with a custom message describing the problem, instead of just returning None. (I haven't tested this, though.)
Yep, that is even better. For some reason I thought doing this would limit the potential of having sub-modules within gi/repository, but testing shows otherwise.
*** This bug has been marked as a duplicate of bug 726877 ***