1# mode: run
2# tag: py3k_super, gh3246
3
4class A(object):
5    def method(self):
6        return 1
7
8    @classmethod
9    def class_method(cls):
10        return 2
11
12    @staticmethod
13    def static_method():
14        return 3
15
16    def generator_test(self):
17        return [1, 2, 3]
18
19
20class B(A):
21    """
22    >>> obj = B()
23    >>> obj.method()
24    1
25    >>> B.class_method()
26    2
27    >>> B.static_method(obj)
28    3
29    >>> list(obj.generator_test())
30    [1, 2, 3]
31    """
32    def method(self):
33        return super().method()
34
35    @classmethod
36    def class_method(cls):
37        return super().class_method()
38
39    @staticmethod
40    def static_method(instance):
41        return super().static_method()
42
43    def generator_test(self):
44        for i in super().generator_test():
45            yield i
46
47
48def test_class_cell_empty():
49    """
50    >>> test_class_cell_empty()
51    Traceback (most recent call last):
52    ...
53    SystemError: super(): empty __class__ cell
54    """
55    class Base(type):
56        def __new__(cls, name, bases, attrs):
57            attrs['foo'](None)
58
59    class EmptyClassCell(metaclass=Base):
60        def foo(self):
61            super()
62
63
64cdef class CClassBase(object):
65    def method(self):
66        return 'def'
67
68#     cpdef method_cp(self):
69#         return 'cpdef'
70#     cdef method_c(self):
71#         return 'cdef'
72#     def call_method_c(self):
73#         return self.method_c()
74
75cdef class CClassSub(CClassBase):
76    """
77    >>> CClassSub().method()
78    'def'
79    """
80#     >>> CClassSub().method_cp()
81#     'cpdef'
82#     >>> CClassSub().call_method_c()
83#     'cdef'
84
85    def method(self):
86        return super().method()
87
88#     cpdef method_cp(self):
89#         return super().method_cp()
90#     cdef method_c(self):
91#         return super().method_c()
92
93
94def freeing_class_cell_temp_gh3246():
95    # https://github.com/cython/cython/issues/3246
96    """
97    >>> abc = freeing_class_cell_temp_gh3246()
98    >>> abc().a
99    1
100    """
101    class SimpleBase(object):
102        def __init__(self):
103            self.a = 1
104
105    class ABC(SimpleBase):
106        def __init__(self):
107            super().__init__()
108
109    return ABC
110