GNOME Bugzilla – Bug 749532
Raise ImportError when override exists but another module does not
Last modified: 2015-06-21 19:54:53 UTC
If an override depends on another module and it does not exist then the ImportError will be assumed to mean that the override does not exist[1]. Instead it should first check if the override module exists and then let any exceptions be raised while loading the override. 1. https://git.gnome.org/browse/pygobject/tree/gi/overrides/__init__.py#n109
Created attachment 303513 [details] [review] Explicitly check if an override exists instead of ImportError If an override depended on another module and it did not exist then the raised ImportError was consumed and assumed to mean that the override did not exist. This makes it difficult to diagnose issues with overrides. This uses pkgutil.get_loader() as it is the easier way to determine if a module exists in both Python 2 and 3 and avoid deprecated functions.
Created attachment 303531 [details] [review] Explicitly check if an override exists instead of ImportError v2 Use my work email address for the commit.
Review of attachment 303531 [details] [review]: ::: gi/overrides/__init__.py @@ +115,3 @@ + override_loader = get_loader(override_package_name) + + except Exception: If the try/except is working around a Python bug which raises an AttributeError, shouldn't we be catching that instead of such a broad exception type?
Created attachment 305736 [details] [review] Explicitly check if an override exists instead of ImportError v3 (In reply to Simon Feltman from comment #3) > Review of attachment 303531 [details] [review] [review]: > > ::: gi/overrides/__init__.py > @@ +115,3 @@ > + override_loader = get_loader(override_package_name) > + > + except Exception: > > If the try/except is working around a Python bug which raises an > AttributeError, shouldn't we be catching that instead of such a broad > exception type? Fixed
Review of attachment 305736 [details] [review]: Looks good, thanks!
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.