[pygi] Don't set a default constructor for structures.
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygi] Don't set a default constructor for structures.
- Date: Fri, 8 Jan 2010 19:35:48 +0000 (UTC)
commit b4189be2b2d3c350fdf33e27309bee5a72e4f72a
Author: Simon van der Linden <svdlinden src gnome org>
Date: Fri Jan 8 20:33:44 2010 +0100
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 +++++++----------------------------
tests/libtestgi.c | 33 ---------------------------------
tests/libtestgi.h | 7 -------
tests/test_gi.py | 21 ++++++++++-----------
4 files changed, 17 insertions(+), 79 deletions(-)
---
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_)
diff --git a/tests/libtestgi.c b/tests/libtestgi.c
index d712b19..a8a77a5 100644
--- a/tests/libtestgi.c
+++ b/tests/libtestgi.c
@@ -3023,39 +3023,6 @@ test_gi__pointer_struct_inout (TestGIPointerStruct **struct_)
}
-TestGIBoxedWithoutConstructorStruct *
-test_gi_boxed_without_constructor_struct_copy (TestGIBoxedWithoutConstructorStruct *struct_)
-{
- TestGIBoxedWithoutConstructorStruct *new_struct;
-
- new_struct = g_slice_new (TestGIBoxedWithoutConstructorStruct);
-
- *new_struct = *struct_;
-
- return new_struct;
-}
-
-static void
-test_gi_boxed_without_constructor_struct_free (TestGIBoxedWithoutConstructorStruct *struct_)
-{
- g_slice_free (TestGIBoxedWithoutConstructorStruct, struct_);
-}
-
-GType
-test_gi_boxed_without_constructor_struct_get_type (void)
-{
- static GType type = 0;
-
- if (type == 0) {
- type = g_boxed_type_register_static ("TestGIBoxedWithoutConstructorStruct",
- (GBoxedCopyFunc) test_gi_boxed_without_constructor_struct_copy,
- (GBoxedFreeFunc) test_gi_boxed_without_constructor_struct_free);
- }
-
- return type;
-}
-
-
TestGIBoxedStruct *
test_gi_boxed_struct_copy (TestGIBoxedStruct *struct_)
{
diff --git a/tests/libtestgi.h b/tests/libtestgi.h
index db12fd3..1620096 100644
--- a/tests/libtestgi.h
+++ b/tests/libtestgi.h
@@ -544,13 +544,6 @@ void test_gi__pointer_struct_inout (TestGIPointerStruct **struct_);
typedef struct {
glong long_;
-} TestGIBoxedWithoutConstructorStruct;
-
-GType test_gi_boxed_without_constructor_struct_get_type (void) G_GNUC_CONST;
-
-
-typedef struct {
- glong long_;
} TestGIBoxedStruct;
GType test_gi_boxed_struct_get_type (void) G_GNUC_CONST;
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 9344edd..8de9114 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1246,29 +1246,28 @@ class TestStructure(unittest.TestCase):
del in_struct
del out_struct
- def test_boxed_without_constructor_struct(self):
- self.assertTrue(issubclass(TestGI.BoxedWithoutConstructorStruct, gobject.GBoxed))
+ def test_boxed_struct(self):
+ self.assertTrue(issubclass(TestGI.BoxedStruct, gobject.GBoxed))
- struct = TestGI.BoxedWithoutConstructorStruct()
+ struct = TestGI.BoxedStruct()
+ self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
- self.assertTrue(isinstance(struct, TestGI.BoxedWithoutConstructorStruct))
+ del struct
- new_struct = struct.copy()
- self.assertTrue(isinstance(new_struct, TestGI.BoxedWithoutConstructorStruct))
+ def test_boxed_struct_new(self):
+ struct = TestGI.BoxedStruct.new()
+ self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
del struct
- del new_struct
- def test_boxed_struct(self):
+ def test_boxed_struct_copy(self):
struct = TestGI.BoxedStruct()
- self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
-
new_struct = struct.copy()
self.assertTrue(isinstance(new_struct, TestGI.BoxedStruct))
- del struct
del new_struct
+ del struct
def test_boxed_struct_return(self):
struct = TestGI.boxed_struct_return()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]