[pygobject] Don't leak internal RepositoryError on import.
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Don't leak internal RepositoryError on import.
- Date: Mon, 26 Oct 2015 08:41:17 +0000 (UTC)
commit 9b821aa0d60857e612cde9dabe9c8f9f9c60214c
Author: Christoph Reiter <creiter src gnome org>
Date: Sun Oct 4 11:13:37 2015 +0200
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
gi/importer.py | 7 +++++--
gi/module.py | 4 ++++
2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gi/importer.py b/gi/importer.py
index 2c4fb9c..5060584 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 f27d516..fd8f508 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]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]