[pygobject] Fix error message when trying to override a non-GI class
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [pygobject] Fix error message when trying to override a non-GI class
- Date: Wed,  4 Apr 2012 14:00:27 +0000 (UTC)
commit 05030a95a4d3090162ed5f510a26d69bbb152942
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Apr 4 15:59:24 2012 +0200
    Fix error message when trying to override a non-GI class
    
    Based on original patch by Juanje Ojeda <jojeda emergya es>.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646667
 gi/overrides/__init__.py |    7 ++++---
 tests/test_overrides.py  |   13 +++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 8ca0cb2..10144e5 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -18,9 +18,10 @@ class _Registry(dict):
         if not key == value:
             raise KeyError('You have tried to modify the registry.  This should only be done by the override decorator')
 
-        info = getattr(value, '__info__')
-        if info == None:
-            raise KeyError('Can not override a type %s, which is not in a gobject introspection typelib' % value.__name__)
+        try:
+            info = getattr(value, '__info__')
+        except AttributeError:
+            raise TypeError('Can not override a type %s, which is not in a gobject introspection typelib' % value.__name__)
 
         if not value.__module__.startswith('gi.overrides'):
             raise KeyError('You have tried to modify the registry outside of the overrides module.  This is not allowed')
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index f0f614c..42f598f 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -19,6 +19,19 @@ import gi.overrides as overrides
 import gi.types
 
 
+class TestRegistry(unittest.TestCase):
+
+    def test_non_gi(self):
+        class MyClass:
+            pass
+
+        try:
+            overrides.override(MyClass)
+            self.fail('unexpected success of overriding non-GI class')
+        except TypeError as e:
+            self.assertTrue('Can not override a type MyClass' in str(e))
+
+
 class TestGLib(unittest.TestCase):
 
     def test_gvariant_create(self):
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]