aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libshiboken/basewrapper.cpp4
-rw-r--r--tests/samplebinding/metaclass_test.py33
2 files changed, 35 insertions, 2 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 1a4a60f52..0fbd3b161 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -285,7 +285,7 @@ void walkThroughClassHierarchy(PyTypeObject* currentType, HierarchyVisitor* visi
for (int i = 0; i < numBases; ++i) {
PyTypeObject* type = reinterpret_cast<PyTypeObject*>(PyTuple_GET_ITEM(bases, i));
- if (type->ob_type != &SbkObjectType_Type) {
+ if (!PyType_IsSubtype(type, reinterpret_cast<PyTypeObject*>(&SbkObject_Type))) {
continue;
} else {
SbkObjectType* sbkType = reinterpret_cast<SbkObjectType*>(type);
@@ -451,7 +451,7 @@ namespace ObjectType
bool checkType(PyTypeObject* type)
{
- return type->ob_type == &SbkObjectType_Type;
+ return PyType_IsSubtype(type, reinterpret_cast<PyTypeObject*>(&SbkObject_Type));
}
bool isUserType(PyTypeObject* type)
diff --git a/tests/samplebinding/metaclass_test.py b/tests/samplebinding/metaclass_test.py
new file mode 100644
index 000000000..3f2ebdaed
--- /dev/null
+++ b/tests/samplebinding/metaclass_test.py
@@ -0,0 +1,33 @@
+from sample import *
+import unittest
+
+class MetaA(type):
+ pass
+
+class A(object):
+ __metaclass__ = MetaA
+
+MetaB = type(Point)
+B = Point
+
+class MetaC(MetaA, MetaB):
+ pass
+class C(A, B):
+ __metaclass__ = MetaC
+
+class D(C):
+ pass
+
+class TestMetaClass(unittest.TestCase):
+ def testIt(self):
+ w1 = C() # works
+ w1.setX(1)
+ w1.setY(2)
+
+ w2 = D() # should work!
+ w2.setX(3)
+ w2.setY(4)
+
+ w3 = w1 + w2
+ self.assertEqual(w3.x(), 4)
+ self.assertEqual(w3.y(), 6)