1PYTHON setup.py build_ext --inplace
2PYTHON -c "import tp_new_tests; tp_new_tests.test_all()"
3PYTHON -c "import tp_new_tests; tp_new_tests.test_sub()"
4
5######## setup.py ########
6
7from Cython.Build.Dependencies import cythonize
8from distutils.core import setup
9
10setup(
11    ext_modules = cythonize("**/*.pyx"),
12    )
13
14######## tp_new_tests.py ########
15
16def test_all():
17    test_a()
18    test_b()
19    test_a_in_b()
20    test_sub()
21
22def test_a():
23    import a
24    assert isinstance(a.tpnew_ExtTypeA(), a.ExtTypeA)
25    assert a.tpnew_ExtTypeA().attrA == 123
26
27def test_b():
28    import b
29    assert isinstance(b.tpnew_ExtTypeB(), b.ExtTypeB)
30    assert b.tpnew_ExtTypeB().attrB == 234
31
32def test_a_in_b():
33    import a,b
34    assert isinstance(b.tpnew_ExtTypeA(), a.ExtTypeA)
35    assert b.tpnew_ExtTypeA().attrA == 123
36
37def test_sub():
38    import b
39    assert isinstance(b.tpnew_SubExtTypeA(), b.SubExtTypeA)
40    assert b.tpnew_SubExtTypeA().attrAB == 345
41    assert b.tpnew_SubExtTypeA().attrA == 123
42
43######## a.pxd ########
44
45cdef api class ExtTypeA[type ExtTypeA_Type, object ExtTypeAObject]:
46    cdef readonly attrA
47
48######## a.pyx ########
49
50cdef class ExtTypeA:
51    def __cinit__(self):
52        self.attrA = 123
53
54def tpnew_ExtTypeA():
55    return ExtTypeA.__new__(ExtTypeA)
56
57######## b.pxd ########
58
59from a cimport ExtTypeA
60
61cdef class ExtTypeB:
62    cdef readonly attrB
63
64cdef class SubExtTypeA(ExtTypeA):
65    cdef readonly attrAB
66
67######## b.pyx ########
68
69from a cimport ExtTypeA
70
71cdef class ExtTypeB:
72    def __cinit__(self):
73        self.attrB = 234
74
75cdef class SubExtTypeA(ExtTypeA):
76    def __cinit__(self):
77        self.attrAB = 345
78
79def tpnew_ExtTypeA():
80    return ExtTypeA.__new__(ExtTypeA)
81
82def tpnew_ExtTypeB():
83    return ExtTypeB.__new__(ExtTypeB)
84
85def tpnew_SubExtTypeA():
86    return SubExtTypeA.__new__(SubExtTypeA)
87