cython

Форк
0
/
ct_DEF.pyx 
262 строки · 9.1 Кб
1
# mode: run
2
# tag: warnings
3

4
cimport cython
5

6
_unicode = unicode
7

8

9
def print_large_number(n):
10
    print(str(n).rstrip('L'))
11

12

13
DEF TUPLE = (1, 2, u"buckle my shoe")
14
DEF TRUE_FALSE = (True, False)
15
DEF NONE = None
16

17
DEF CHAR = c'x'
18
DEF INT0 = -1
19
DEF INT1 = 42
20
DEF INT2 = 0x42
21
DEF INT3 = -0x42
22
DEF LONG = 666L
23
DEF LARGE_NUM32 = (1 << 32) - 1
24
DEF LARGE_NUM64 = (1 << 64) - 1
25
DEF FLOAT = 12.5
26
DEF EXACT_FLOAT = 0.577215664901532860606512090082402431
27
DEF E_FLOAT = 0.5772156E4  # Cannot currently warn about this since we can't safely compare the string repr.
28
DEF BYTES = b"spam"
29
DEF UNICODE = u"spam-u"
30
DEF TWO = TUPLE[1]
31
DEF FIVE = TWO + 3
32
DEF TRUE  = TRUE_FALSE[0]
33
DEF FALSE = TRUE_FALSE[1]
34
DEF INT_TUPLE1 = TUPLE[:2]
35
DEF INT_TUPLE2 = TUPLE[1:4:2]
36
DEF ELLIPSIS = ...
37
DEF EXPRESSION = int(float(2*2)) + int(str(2)) + int(max(1,2,3)) + sum([TWO, FIVE])
38
DEF UNICODE_EXPRESSION = unicode(BYTES.decode('utf8')).encode('ascii').decode('latin1')
39

40

41
def c():
42
    """
43
    >>> c()
44
    120
45
    """
46
    cdef char c = CHAR
47
    return c
48

49
def i0():
50
    """
51
    >>> i0() == -1
52
    True
53
    """
54
    cdef int i = INT0
55
    return i
56

57
def i1():
58
    """
59
    >>> i1() == 42
60
    True
61
    """
62
    cdef int i = INT1
63
    return i
64

65
def i2():
66
    """
67
    >>> i2() == 0x42
68
    True
69
    """
70
    cdef int i = INT2
71
    return i
72

73
def i3():
74
    """
75
    >>> i3() == -0x42
76
    True
77
    """
78
    cdef int i = INT3
79
    return i
80

81
def l():
82
    """
83
    >>> l()
84
    666
85
    """
86
    cdef long l = LONG
87
    return l
88

89
def large_nums():
90
    """
91
    >>> ul32, ul64, l64, n64 = large_nums()
92
    >>> print_large_number(ul32)
93
    4294967295
94
    >>> print_large_number(ul64)
95
    18446744073709551615
96
    >>> print_large_number(l64)
97
    4294967295
98
    >>> print_large_number(n64)
99
    -4294967295
100
    """
101
    cdef unsigned long ul32 = LARGE_NUM32
102
    cdef unsigned long long ul64 = LARGE_NUM64
103
    cdef long long l64 = LARGE_NUM32
104
    cdef long long n64 = -LARGE_NUM32
105
    return ul32, ul64, l64, n64
106

107
def f():
108
    """
109
    >>> f()
110
    12.5
111
    """
112
    cdef float f = FLOAT
113
    return f
114

115
def s():
116
    """
117
    >>> s()
118
    b'spam'
119
    """
120
    cdef char* s = BYTES
121
    return s
122

123
def type_of_bytes():
124
    """
125
    >>> t, s = type_of_bytes()
126
    >>> assert t is bytes, t
127
    >>> assert type(s) is bytes, type(s)
128
    """
129
    t = type(BYTES)
130
    s = BYTES
131
    return t, s
132

133
def type_of_unicode():
134
    """
135
    >>> t, s = type_of_unicode()
136
    >>> assert t is _unicode, t
137
    >>> assert type(s) is _unicode, type(s)
138
    """
139
    t = type(UNICODE)
140
    s = UNICODE
141
    return t, s
142

143
@cython.test_assert_path_exists('//TupleNode')
144
def constant_tuple():
145
    """
146
    >>> constant_tuple()[:-1]
147
    (1, 2)
148
    >>> print(constant_tuple()[-1])
149
    buckle my shoe
150
    """
151
    cdef object t = TUPLE
152
    return t
153

154
@cython.test_assert_path_exists('//IntNode')
155
def tuple_indexing():
156
    """
157
    >>> tuple_indexing()
158
    2
159
    """
160
    cdef int two = INT_TUPLE1[-1]
161
    return two
162

163
def two():
164
    """
165
    >>> two()
166
    2
167
    """
168
    cdef int two = TWO
169
    return two
170

171
def five():
172
    """
173
    >>> five()
174
    5
175
    """
176
    cdef int five = FIVE
177
    return five
178

179
@cython.test_assert_path_exists('//BoolNode')
180
def true():
181
    """
182
    >>> true()
183
    True
184
    """
185
    cdef bint true = TRUE
186
    return true
187

188
@cython.test_assert_path_exists('//BoolNode')
189
def false():
190
    """
191
    >>> false()
192
    False
193
    """
194
    cdef bint false = FALSE
195
    return false
196

197
def ellipsis():
198
    """
199
    >>> ellipsis()
200
    Ellipsis
201
    """
202
    return ELLIPSIS
203

204
@cython.test_assert_path_exists('//IntNode')
205
@cython.test_fail_if_path_exists('//AddNode')
206
def expression():
207
    """
208
    >>> expression()
209
    16
210
    """
211
    cdef int i = EXPRESSION
212
    return i
213

214

215
def unicode_expression():
216
    """
217
    >>> print(unicode_expression())
218
    spam
219
    """
220
    s = UNICODE_EXPRESSION
221
    return s
222

223

224
def none():
225
    """
226
    >>> none()
227
    """
228
    return NONE
229

230

231
_IGNORE = """
232
24:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
233
25:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
234
26:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
235
28:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
236
29:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
237
30:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
238
31:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
239
32:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
240
33:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
241
34:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
242
35:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
243
36:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
244
37:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
245
37:18: Using this floating point value with DEF may lose precision, using 0.5772156649015329
246
38:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
247
39:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
248
40:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
249
41:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
250
42:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
251
43:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
252
44:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
253
45:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
254
46:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
255
47:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
256
48:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
257
49:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
258
"""
259

260
_WARNINGS = """
261
26:18: Using this floating point value with DEF may lose precision, using 0.5772156649015329
262
"""
263

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

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

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

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