From 3fcfc62da07f088c79413fb782b4d8073a5d1c37 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 30 Oct 2010 19:35:26 +0200 Subject: [PATCH] prevent subtyping final types in Cython (inside of the same module) --- Cython/Compiler/Nodes.py | 7 ++++++- tests/errors/subtyping_final_class.pyx | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/errors/subtyping_final_class.pyx 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 +""" -- 2.26.2