cython

Форк
0
/
cclass_assign_attr_GH3100.pyx 
62 строки · 1.5 Кб
1
cdef extern from *:
2
    """
3
    #ifdef CYTHON_USE_TYPE_SPECS
4
    #define TYPESPECS 1
5
    #else
6
    #define TYPESPECS 0
7
    #endif
8
    """
9
    int TYPESPECS
10

11
cdef class Foo:
12
    """
13
    >>> D = Foo.__dict__
14
    >>> D["meth"] is D["meth2"]
15
    True
16
    >>> D["classmeth"] is D["classmeth2"]
17
    True
18
    >>> D["staticmeth"] is D["staticmeth2"]
19
    True
20
    """
21
    def meth(self): pass
22
    @classmethod
23
    def classmeth(cls): pass
24
    @staticmethod
25
    def staticmeth(): pass
26

27
    meth2 = meth
28
    classmeth2 = classmeth
29
    staticmeth2 = staticmeth
30

31
cdef class ChangeName:
32
    # the class seems to need some contents for changing the
33
    # name to cause a problem
34
    cdef public str attr1
35
    cdef public int attr2
36

37
if TYPESPECS:
38
    __doc__ = """
39
    For typespecs, cdef classes are mutable on some Python versions
40
    (and it's easiest to leave them that way). Therefore the test
41
    is 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
    """
48
else:
49
    __doc__ = """
50
    GH-5079
51
    Assigning to the cdef class name shouldn't cause a crash.
52
    The important bit of this test is the not crashing - it's
53
    possible that typespec/limited-API defined classes will be
54
    naturally mutable and that isn't a huge problem
55

56
    >>> ChangeName.__name__ = "SomethingElse"  # doctest: +ELLIPSIS
57
    Traceback (most recent call last):
58
        ...
59
    TypeError: ...
60
    >>> ChangeName.__name__
61
    'ChangeName'
62
    """
63

64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.