Commit 05030a95 authored by Martin Pitt's avatar Martin Pitt
Browse files

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
parent 96f14989
......@@ -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')
......
......@@ -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):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment