From: Stefan Behnel Date: Sat, 4 Dec 2010 11:54:05 +0000 (+0100) Subject: prevent inheriting from PyVarObjects: tuple, bytes and str X-Git-Tag: 0.14.alpha0~19 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=12b64d687e1c69e96a178c17d6e5d63eedfe5939;p=cython.git prevent inheriting from PyVarObjects: tuple, bytes and str --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 6fc38988..63528fbc 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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 index 00000000..79ff24a5 --- /dev/null +++ b/tests/errors/builtin_type_inheritance.pyx @@ -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 +"""