From b4189be2b2d3c350fdf33e27309bee5a72e4f72a Mon Sep 17 00:00:00 2001 From: Simon van der Linden Date: Fri, 8 Jan 2010 20:33:44 +0100 Subject: Don't set a default constructor for structures. Update tests accordingly. The reason for this change is that setting __new__ in the metaclass doesn't let one overrides it afterwards, in a subclass (in my experience, at least, even though it seems weird). https://bugzilla.gnome.org/show_bug.cgi?id=603536 --- gi/types.py | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) (limited to 'gi') diff --git a/gi/types.py b/gi/types.py index 5212fef..e4d7c5f 100644 --- a/gi/types.py +++ b/gi/types.py @@ -61,6 +61,13 @@ def Constructor(info): class MetaClassHelper(object): + def _setup_constructors(cls): + for method_info in cls.__info__.get_methods(): + if method_info.is_constructor(): + name = method_info.get_name() + constructor = classmethod(Constructor(method_info)) + setattr(cls, name, constructor) + def _setup_methods(cls): for method_info in cls.__info__.get_methods(): name = method_info.get_name() @@ -87,13 +94,6 @@ class MetaClassHelper(object): class GObjectMeta(gobject.GObjectMeta, MetaClassHelper): - def _setup_constructors(cls): - for method_info in cls.__info__.get_methods(): - if method_info.is_constructor(): - name = method_info.get_name() - constructor = classmethod(Constructor(method_info)) - setattr(cls, name, constructor) - def __init__(cls, name, bases, dict_): super(GObjectMeta, cls).__init__(name, bases, dict_) @@ -114,27 +114,6 @@ class GObjectMeta(gobject.GObjectMeta, MetaClassHelper): class StructMeta(type, MetaClassHelper): - def _setup_constructors(cls): - constructor_infos = [] - default_constructor_info = None - - for method_info in cls.__info__.get_methods(): - if method_info.is_constructor(): - name = method_info.get_name() - constructor = classmethod(Function(method_info)) - - setattr(cls, name, constructor) - - constructor_infos.append(method_info) - if name == "new": - default_constructor_info = method_info - - if default_constructor_info is None and constructor_infos: - default_constructor_info = constructor_infos[0] - - if default_constructor_info is not None: - cls.__new__ = staticmethod(Function(default_constructor_info)) - def __init__(cls, name, bases, dict_): super(StructMeta, cls).__init__(name, bases, dict_) -- cgit