cython
1cdef extern from *:
2"""
3#ifdef CYTHON_USE_TYPE_SPECS
4#define TYPESPECS 1
5#else
6#define TYPESPECS 0
7#endif
8"""
9int TYPESPECS
10
11cdef class Foo:
12"""
13>>> D = Foo.__dict__
14>>> D["meth"] is D["meth2"]
15True
16>>> D["classmeth"] is D["classmeth2"]
17True
18>>> D["staticmeth"] is D["staticmeth2"]
19True
20"""
21def meth(self): pass
22@classmethod
23def classmeth(cls): pass
24@staticmethod
25def staticmeth(): pass
26
27meth2 = meth
28classmeth2 = classmeth
29staticmeth2 = staticmeth
30
31cdef class ChangeName:
32# the class seems to need some contents for changing the
33# name to cause a problem
34cdef public str attr1
35cdef public int attr2
36
37if TYPESPECS:
38__doc__ = """
39For typespecs, cdef classes are mutable on some Python versions
40(and it's easiest to leave them that way). Therefore the test
41is just that reassigning the name doesn't cause a crash
42
43>>> try:
44... ChangeName.__name__ = "SomethingElse"
45... except TypeError:
46... pass # either type error or changing the name is fine
47"""
48else:
49__doc__ = """
50GH-5079
51Assigning to the cdef class name shouldn't cause a crash.
52The important bit of this test is the not crashing - it's
53possible that typespec/limited-API defined classes will be
54naturally mutable and that isn't a huge problem
55
56>>> ChangeName.__name__ = "SomethingElse" # doctest: +ELLIPSIS
57Traceback (most recent call last):
58...
59TypeError: ...
60>>> ChangeName.__name__
61'ChangeName'
62"""
63
64