1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
PYTHON setup.py build_ext --inplace
PYTHON -c "import runner"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(ext_modules=cythonize("*.pyx"))
######## notheaptype.pyx ########
cdef class Base:
pass
Obj = type(object())
cdef class Foo(Base, Obj):
pass
######## wrongbase.pyx ########
cdef class Base:
pass
Str = type("")
cdef class X(Base, Str):
pass
######## badmro.pyx ########
class Py(object):
pass
cdef class X(object, Py):
pass
######## nodict.pyx ########
cdef class Base:
pass
class Py(object):
pass
cdef class X(Base, Py):
pass
######## oldstyle.pyx ########
# cython: language_level=2
cdef class Base:
cdef dict __dict__
class OldStyle:
pass
cdef class Foo(Base, OldStyle):
pass
######## runner.py ########
import sys
try:
import notheaptype
assert False, "notheaptype"
except TypeError as msg:
assert str(msg) == "base class 'object' is not a heap type"
try:
import wrongbase
assert False, "wrongbase"
except TypeError as msg:
assert str(msg) == "best base 'str' must be equal to first base 'wrongbase.Base'"
try:
import badmro
assert False, "badmro"
except TypeError as msg:
assert str(msg).startswith("Cannot create a consistent method resolution")
try:
import nodict
assert False, "nodict"
except TypeError as msg:
assert str(msg) == "extension type 'nodict.X' has no __dict__ slot, but base type 'Py' has: either add 'cdef dict __dict__' to the extension type or add '__slots__ = [...]' to the base type"
try:
# This should work on Python 3 but fail on Python 2
import oldstyle
assert sys.version_info[0] >= 3, "oldstyle"
except TypeError as msg:
assert str(msg) == "base class 'OldStyle' is an old-style class"
|