1# mode: run
2# ticket: 568
3
4cimport cython
5
6@cython.final
7cdef class FinalType(object):
8    """
9    >>> obj = FinalType()
10    >>> obj.test_cdef()
11    >>> obj.test_cpdef()
12    """
13
14    @cython.test_assert_path_exists("//CFuncDefNode[@entry.is_final_cmethod=True]")
15    cdef cdef_method(self):
16        pass
17
18    @cython.test_assert_path_exists("//CFuncDefNode[@entry.is_final_cmethod=True]")
19    @cython.test_fail_if_path_exists("//CFuncDefNode//OverrideCheckNode")
20    cpdef cpdef_method(self):
21        pass
22
23    @cython.test_assert_path_exists("//AttributeNode[@entry.is_final_cmethod=True]")
24    def test_cdef(self):
25        self.cdef_method()
26
27    @cython.test_assert_path_exists("//AttributeNode[@entry.is_final_cmethod=True]")
28    def test_cpdef(self):
29        self.cpdef_method()
30
31
32def test_external_call():
33    """
34    >>> test_external_call()
35    """
36    f = FinalType()
37    return f.cpdef_method()
38
39def test_external_call_in_temp():
40    """
41    >>> test_external_call_in_temp()
42    """
43    return FinalType().cpdef_method()
44
45
46cdef class BaseTypeWithFinalMethods(object):
47    """
48    >>> obj = BaseTypeWithFinalMethods()
49    >>> obj.test_cdef()
50    """
51
52    @cython.test_assert_path_exists("//CFuncDefNode[@entry.is_final_cmethod=True]")
53    @cython.final
54    cdef cdef_method(self):
55        pass
56
57    @cython.test_assert_path_exists("//AttributeNode[@entry.is_final_cmethod=True]")
58    def test_cdef(self):
59        self.cdef_method()
60
61
62cdef class SubType(BaseTypeWithFinalMethods):
63    """
64    >>> obj = SubType()
65    >>> obj.test_cdef()
66    """
67    @cython.test_assert_path_exists("//AttributeNode[@entry.is_final_cmethod=True]")
68    def test_cdef(self):
69        self.cdef_method()
70