cython

Форк
0
/
py_hash_t.pyx 
48 строк · 878.0 Байт
1

2
cimport cython
3

4

5
class IntLike(object):
6
  def __init__(self, value):
7
    self.value = value
8
  def __index__(self):
9
    return self.value
10

11

12
def assign_py_hash_t(x):
13
    """
14
    >>> assign_py_hash_t(12)
15
    12
16
    >>> assign_py_hash_t(-12)
17
    -12
18

19
    >>> assign_py_hash_t(IntLike(-3))
20
    -3
21
    >>> assign_py_hash_t(IntLike(1 << 100))  # doctest: +ELLIPSIS
22
    Traceback (most recent call last):
23
    ...
24
    OverflowError: ...
25
    >>> assign_py_hash_t(IntLike(1.5))  # doctest: +ELLIPSIS
26
    Traceback (most recent call last):
27
    ...
28
    TypeError: __index__ ... (type ...float...)
29
    """
30
    cdef Py_hash_t h = x
31
    return h
32

33

34
def infer_hash_type(x):
35
    """
36
    >>> infer_hash_type(123)
37
    'Py_hash_t'
38
    """
39
    h = hash(x)
40
    return cython.typeof(h)
41

42

43
def assign_to_name(x):
44
    """
45
    >>> assign_to_name(321)
46
    321
47
    """
48
    Py_hash_t = x
49
    return Py_hash_t
50

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

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

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

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