cython

Форк
0
/
builtinnames.pyx 
59 строк · 1.4 Кб
1
cimport cython
2

3
def test_file_py(file):
4
    assert isinstance(file, (str, unicode)), \
5
        u"not a string, found '%s' instead" % file.__class__.__name__
6
    return file
7

8
cdef test_file_c(file):
9
    assert isinstance(file, (str, unicode)), \
10
        u"not a string, found '%s' instead" % file.__class__.__name__
11
    return u'file' + file
12

13

14
def range(arg):
15
    return u'range' + arg
16

17
def len(arg):
18
    return u'len' + arg
19

20
cdef type(arg):
21
    return u'type' + arg
22

23

24
@cython.test_fail_if_path_exists(
25
    '//PyMethodCallNode/NameNode[@name="type" and @entry.is_cfunction=False]',
26
    '//SimpleCallNode/NameNode[@name="type" and @entry.is_cfunction=False]',
27
    '//SimpleCallNode/NameNode[@name="len" and @entry.is_cfunction=True]',
28
    )
29
@cython.test_assert_path_exists(
30
    '//SimpleCallNode/NameNode[@name="type"]',
31
    '//SimpleCallNode/NameNode[@name="type" and @entry.is_cfunction=True]',
32
    '//PyMethodCallNode/NameNode[@name="len"]',
33
    )
34
def test_c(arg):
35
    """
36
    >>> test_c('abc')
37
    fileabc
38
    lenabc
39
    typeabc
40
    >>> print(test_file_py('abc'))
41
    abc
42
    >>> print(range('abc'))
43
    rangeabc
44
    >>> print(len('abc'))
45
    lenabc
46
    """
47
    print test_file_c(arg)
48
    print len(arg)
49
    print type(arg)
50

51
def test_for_in_range(arg):
52
    """
53
    >>> print(str(test_for_in_range('abc')).replace("u'", "'"))
54
    ['r', 'a', 'n', 'g', 'e', 'a', 'b', 'c']
55
    """
56
    l = []
57
    for c in range(arg):
58
        l.append(c)
59
    return l
60

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

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

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

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