From: Stefan Behnel Date: Sat, 30 Oct 2010 17:35:26 +0000 (+0200) Subject: prevent subtyping final types in Cython (inside of the same module) X-Git-Tag: 0.14.alpha0~279 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3fcfc62da07f088c79413fb782b4d8073a5d1c37;p=cython.git prevent subtyping final types in Cython (inside of the same module) --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index a7c95926..e109b507 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3104,7 +3104,12 @@ class CClassDefNode(ClassDefNode): elif not base_class_entry.type.is_extension_type: error(self.pos, "'%s' is not an extension type" % self.base_class_name) elif not base_class_entry.type.is_complete(): - error(self.pos, "Base class '%s' is incomplete" % self.base_class_name) + error(self.pos, "Base class '%s' of type '%s' is incomplete" % ( + self.base_class_name, self.class_name)) + elif base_class_entry.type.scope and base_class_entry.type.scope.directives and \ + base_class_entry.type.scope.directives.get('final', False): + error(self.pos, "Base class '%s' of type '%s' is final" % ( + self.base_class_name, self.class_name)) else: self.base_type = base_class_entry.type has_body = self.body is not None diff --git a/tests/errors/subtyping_final_class.pyx b/tests/errors/subtyping_final_class.pyx new file mode 100644 index 00000000..477669b1 --- /dev/null +++ b/tests/errors/subtyping_final_class.pyx @@ -0,0 +1,13 @@ + +cimport cython + +@cython.final +cdef class FinalClass: + pass + +cdef class SubType(FinalClass): + pass + +_ERRORS = """ +8:5: Base class 'FinalClass' of type 'SubType' is final +"""