From cc0e8423f36486d15f751bd3c14351edda28538d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20Fr=C3=A9cinaux?= Date: Mon, 4 Apr 2011 21:12:18 +0200 Subject: Fix ABI break in old static bindings. Commit 84d6142c14a7ebfb7284d3db52e14d3393f93905 (Always register a new GType when a GObject class is subclassed) breaks the more advanced usage of PyGObject with regards to "metaclass hackery" as used in for example the kiwi and sqlkit projects. But the users of the gi-based bindings now rely on the new behaviour. We fix this by restraining the systematical registering of new types to the new gi-based bindings, leaving the old pygtk ones untouched. https://bugzilla.gnome.org/show_bug.cgi?id=646437 --- gi/types.py | 9 +++++++++ gobject/__init__.py | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gi/types.py b/gi/types.py index 9b250b16..210fdc1c 100644 --- a/gi/types.py +++ b/gi/types.py @@ -232,6 +232,15 @@ class GObjectMeta(gobject.GObjectMeta, MetaClassHelper): def mro(cls): return mro(cls) + def _must_register_type(cls, namespace): + ## don't register the class if already registered + if '__gtype__' in namespace: + return False + + # Do not register a new GType for the overrides, as this would sort of + # defeat the purpose of overrides... + return not cls.__module__.startswith('gi.overrides.') + def mro(C): """Compute the class precedence list (mro) according to C3 diff --git a/gobject/__init__.py b/gobject/__init__.py index 1858d188..a9522a63 100644 --- a/gobject/__init__.py +++ b/gobject/__init__.py @@ -101,17 +101,19 @@ class GObjectMeta(type): prop.setter(self, value) cls.do_set_property = obj_set_property - def _type_register(cls, namespace): + def _must_register_type(cls, namespace): ## don't register the class if already registered if '__gtype__' in namespace: - return + return False - # Do not register a new GType for the overrides, as this would sort of - # defeat the purpose of overrides... - if cls.__module__.startswith('gi.overrides.'): - return + return ('__gproperties__' in namespace or + '__gsignals__' in namespace or + '__gtype_name__' in namespace) + + def _type_register(cls, namespace): + if cls._must_register_type(namespace): + type_register(cls, namespace.get('__gtype_name__')) - type_register(cls, namespace.get('__gtype_name__')) _gobject._install_metaclass(GObjectMeta) del _gobject -- cgit v1.2.1