prevent inheriting from PyVarObjects: tuple, bytes and str
authorStefan Behnel <scoder@users.berlios.de>
Sat, 4 Dec 2010 11:54:05 +0000 (12:54 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 4 Dec 2010 11:54:05 +0000 (12:54 +0100)
Cython/Compiler/Nodes.py
tests/errors/builtin_type_inheritance.pyx [new file with mode: 0644]

index 6fc38988dd35f7c7e45a9614c60376fc2bf102dc..63528fbcfe4331deb14013bb23d92be41e9ab17e 100644 (file)
@@ -3203,6 +3203,10 @@ class CClassDefNode(ClassDefNode):
                              base_class_entry.type.scope.directives['final']:
                         error(self.pos, "Base class '%s' of type '%s' is final" % (
                             self.base_class_name, self.class_name))
+                    elif base_class_entry.type.is_builtin_type and \
+                             base_class_entry.type.name in ('tuple', 'str', 'bytes'):
+                        error(self.pos, "inheritance from PyVarObject types like '%s' is not currently supported"
+                              % base_class_entry.type.name)
                     else:
                         self.base_type = base_class_entry.type
         has_body = self.body is not None
diff --git a/tests/errors/builtin_type_inheritance.pyx b/tests/errors/builtin_type_inheritance.pyx
new file mode 100644 (file)
index 0000000..79ff24a
--- /dev/null
@@ -0,0 +1,17 @@
+
+# current restriction: cannot inherit from PyVarObject (see ticket #152)
+
+cdef class MyTuple(tuple):
+    pass
+
+cdef class MyBytes(bytes):
+    pass
+
+cdef class MyStr(str): # only in Py2, but can't know that during compilation
+    pass
+
+_ERRORS = """
+4:5: inheritance from PyVarObject types like 'tuple' is not currently supported
+7:5: inheritance from PyVarObject types like 'bytes' is not currently supported
+10:5: inheritance from PyVarObject types like 'str' is not currently supported
+"""