cython

Форк
0
/
typing_module.py 
42 строки · 1.0 Кб
1
# mode: run
2
# tag: pure3.6
3

4
from __future__ import print_function
5

6
import cython
7

8
try:
9
    import typing
10
    from typing import List
11
    from typing import Set as _SET_
12
except ImportError:
13
    pass  # this should allow Cython to interpret the directives even when the module doesn't exist
14

15

16
def test_subscripted_types():
17
    """
18
    >>> test_subscripted_types()
19
    dict object
20
    list object
21
    set object
22
    """
23
    a: typing.Dict[int, float] = {}
24
    b: List[int] = []
25
    c: _SET_[object] = set()
26

27
    print(cython.typeof(a) + (" object" if not cython.compiled else ""))
28
    print(cython.typeof(b) + (" object" if not cython.compiled else ""))
29
    print(cython.typeof(c) + (" object" if not cython.compiled else ""))
30

31
@cython.cclass
32
class TestClassVar:
33
    """
34
    >>> TestClassVar.cls
35
    5
36
    >>> TestClassVar.regular  # doctest: +IGNORE_EXCEPTION_DETAIL
37
    Traceback (most recent call last):
38
        ...
39
    AttributeError:
40
    """
41
    regular: int
42
    cls: typing.ClassVar[int] = 5  # this is a little redundant really because the assignment ensures it
43

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

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

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

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