cython

Форк
0
/
methodmangling_pure.py 
76 строк · 1.9 Кб
1
# mode: run
2
# cython: language_level=3
3

4
# This file tests that methodmangling is applied correctly to
5
# pure Python decorated classes.
6

7
import cython
8

9
if cython.compiled:
10
    # don't run in Python mode since a significant number of the tests
11
    # are only for Cython features
12

13
    def declare(**kwargs):
14
        return kwargs['__x']
15

16
    class RegularClass:
17
        @cython.locals(__x=cython.int)
18
        def f1(self, __x, dummy=None):
19
            """
20
            Is the locals decorator correctly applied
21
            >>> c = RegularClass()
22
            >>> c.f1(1)
23
            1
24
            >>> c.f1("a")
25
            Traceback (most recent call last):
26
            ...
27
            TypeError: an integer is required
28
            >>> c.f1(_RegularClass__x = 1)
29
            1
30
            """
31
            return __x
32

33
        def f2(self, x):
34
            """
35
            Is the locals decorator correctly applied
36
            >>> c = RegularClass()
37
            >>> c.f2(1)
38
            1
39
            >>> c.f2("a")
40
            Traceback (most recent call last):
41
            ...
42
            TypeError: an integer is required
43
            """
44
            __x = cython.declare(cython.int, x)
45

46
            return __x
47

48
        def f3(self, x):
49
            """
50
            Is the locals decorator correctly applied
51
            >>> c = RegularClass()
52
            >>> c.f3(1)
53
            1
54
            >>> c.f3("a")
55
            Traceback (most recent call last):
56
            ...
57
            TypeError: an integer is required
58
            """
59
            cython.declare(__x=cython.int)
60
            __x = x
61

62
            return __x
63

64
        def f4(self, x):
65
            """
66
            We shouldn't be tripped up by a function called
67
            "declare" that is nothing to do with cython
68
            >>> RegularClass().f4(1)
69
            1
70
            """
71
            return declare(__x=x)
72
else:
73
    __doc__ = """
74
    >>> True
75
    True
76
    """  # stops Python2 from failing
77

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

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

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

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