summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <creiter@src.gnome.org>2015-10-04 11:13:37 +0200
committerChristoph Reiter <creiter@src.gnome.org>2015-10-26 09:27:53 +0100
commit9b821aa0d60857e612cde9dabe9c8f9f9c60214c (patch)
treec908167ba6921506b770a581475bb8917ebb65b6
parentdba1da9b0770c7dec1abd82303b9b4266fe2ce3f (diff)
downloadpygobject-9b821aa0d60857e612cde9dabe9c8f9f9c60214c.tar.gz
Don't leak internal RepositoryError on import.
In case a dependency of the imported namespace has a version conflict with an already loaded version, import would raise RepositoryError. This fixes it to raise an ImportError instead. https://bugzilla.gnome.org/show_bug.cgi?id=756033
-rw-r--r--gi/importer.py7
-rw-r--r--gi/module.py4
2 files changed, 9 insertions, 2 deletions
diff --git a/gi/importer.py b/gi/importer.py
index 2c4fb9cc..50605842 100644
--- a/gi/importer.py
+++ b/gi/importer.py
@@ -28,7 +28,7 @@ import importlib
from contextlib import contextmanager
import gi
-from ._gi import Repository
+from ._gi import Repository, RepositoryError
from ._gi import PyGIWarning
from .module import get_introspection_module
from .overrides import load_overrides
@@ -116,7 +116,10 @@ class DynamicImporter(object):
else:
stacklevel = 4
with _check_require_version(namespace, stacklevel=stacklevel):
- introspection_module = get_introspection_module(namespace)
+ try:
+ introspection_module = get_introspection_module(namespace)
+ except RepositoryError as e:
+ raise ImportError(e)
# Import all dependencies first so their init functions
# (gdk_init, ..) in overrides get called.
# https://bugzilla.gnome.org/show_bug.cgi?id=656314
diff --git a/gi/module.py b/gi/module.py
index f27d516d..fd8f5080 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -117,6 +117,8 @@ class IntrospectionModule(object):
These members are then cached on this introspection module.
"""
def __init__(self, namespace, version=None):
+ """Might raise gi._gi.RepositoryError"""
+
repository.require(namespace, version)
self._namespace = namespace
self._version = version
@@ -263,6 +265,8 @@ def get_introspection_module(namespace):
"""
:Returns:
An object directly wrapping the gi module without overrides.
+
+ Might raise gi._gi.RepositoryError
"""
if namespace in _introspection_modules:
return _introspection_modules[namespace]