[pygobject] Explicitly check if an override exists instead of ImportError
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Explicitly check if an override exists instead of ImportError
- Date: Sun, 21 Jun 2015 19:53:11 +0000 (UTC)
commit 79cf1f70d247b5a4d33d1e60107e47903ca76055
Author: Garrett Regier <garrett regier riftio com>
Date: Mon May 18 02:32:18 2015 -0700
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.
https://bugzilla.gnome.org/show_bug.cgi?id=749532
gi/overrides/__init__.py | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index bc915b2..942e6ed 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -2,6 +2,7 @@ import types
import warnings
import importlib
import sys
+from pkgutil import get_loader
from gi import PyGIDeprecationWarning
from gi._gi import CallableInfo
@@ -107,10 +108,22 @@ def load_overrides(introspection_module):
modules[namespace] = proxy
try:
+ override_package_name = 'gi.overrides.' + namespace
+
+ # http://bugs.python.org/issue14710
try:
- override_mod = importlib.import_module('gi.overrides.' + namespace)
- except ImportError:
+ override_loader = get_loader(override_package_name)
+
+ except AttributeError:
+ override_loader = None
+
+ # Avoid checking for an ImportError, an override might
+ # depend on a missing module thus causing an ImportError
+ if override_loader is None:
return introspection_module
+
+ override_mod = importlib.import_module(override_package_name)
+
finally:
del modules[namespace]
del sys.modules[module_key]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]