cython
1# mode: run
2# tag: pure3.6
3
4from __future__ import print_function
5
6import cython
7
8try:
9import typing
10from typing import List
11from typing import Set as _SET_
12except ImportError:
13pass # this should allow Cython to interpret the directives even when the module doesn't exist
14
15
16def test_subscripted_types():
17"""
18>>> test_subscripted_types()
19dict object
20list object
21set object
22"""
23a: typing.Dict[int, float] = {}
24b: List[int] = []
25c: _SET_[object] = set()
26
27print(cython.typeof(a) + (" object" if not cython.compiled else ""))
28print(cython.typeof(b) + (" object" if not cython.compiled else ""))
29print(cython.typeof(c) + (" object" if not cython.compiled else ""))
30
31@cython.cclass
32class TestClassVar:
33"""
34>>> TestClassVar.cls
355
36>>> TestClassVar.regular # doctest: +IGNORE_EXCEPTION_DETAIL
37Traceback (most recent call last):
38...
39AttributeError:
40"""
41regular: int
42cls: typing.ClassVar[int] = 5 # this is a little redundant really because the assignment ensures it
43