aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/g/generic_alias/generic_alias_collections.py
blob: 33f6b6e2c3ec29e04d7efe2870f39aac1cf46cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""Test generic alias support for stdlib types (added in PY39)."""
# flake8: noqa
# pylint: disable=missing-docstring,pointless-statement
# pylint: disable=too-few-public-methods,multiple-statements,line-too-long
import abc
import collections
import collections.abc
import contextlib
import re

# special
tuple[int, int]
type[int]
collections.abc.Callable[[int], str]

# builtins
dict[int, str]
list[int]
set[int]
frozenset[int]

# collections
collections.defaultdict[int, str]
collections.OrderedDict[int, str]
collections.ChainMap[int, str]
collections.Counter[int]
collections.deque[int]

# collections.abc
collections.abc.Set[int]
collections.abc.Collection[int]
collections.abc.Container[int]
collections.abc.ItemsView[int, str]
collections.abc.KeysView[int]
collections.abc.Mapping[int, str]
collections.abc.MappingView[int]
collections.abc.MutableMapping[int, str]
collections.abc.MutableSequence[int]
collections.abc.MutableSet[int]
collections.abc.Sequence[int]
collections.abc.ValuesView[int]

collections.abc.Iterable[int]
collections.abc.Iterator[int]
collections.abc.Generator[int, None, None]
collections.abc.Reversible[int]

collections.abc.Coroutine[list[str], str, int]
collections.abc.AsyncGenerator[int, None]
collections.abc.AsyncIterable[int]
collections.abc.AsyncIterator[int]
collections.abc.Awaitable[int]

# contextlib
contextlib.AbstractContextManager[int]
contextlib.AbstractAsyncContextManager[int]

# re
re.Pattern[str]
re.Match[str]


# unsubscriptable types
collections.abc.Hashable
collections.abc.Sized
collections.abc.Hashable[int]  # [unsubscriptable-object]
collections.abc.Sized[int]  # [unsubscriptable-object]

# subscriptable with Python 3.9
collections.abc.ByteString[int]


# Missing implementation for 'collections.abc' derived classes
class DerivedHashable(collections.abc.Hashable):  # [abstract-method]  # __hash__
    pass

class DerivedIterable(collections.abc.Iterable[int]):  # [abstract-method]  # __iter__
    pass

class DerivedCollection(collections.abc.Collection[int]):  # [abstract-method,abstract-method,abstract-method]  # __contains__, __iter__, __len__
    pass


# No implementation required for 'builtins' and 'collections' types
class DerivedList(list[int]):
    pass

class DerivedSet(set[int]):
    pass

class DerivedOrderedDict(collections.OrderedDict[int, str]):
    pass

class DerivedListIterable(list[collections.abc.Iterable[int]]):
    pass


# Multiple generic base classes
class DerivedMultiple(collections.abc.Sized, collections.abc.Hashable):  # [abstract-method,abstract-method]
    pass

class CustomAbstractCls1(abc.ABC):
    pass
class CustomAbstractCls2(collections.abc.Sized, collections.abc.Iterable[CustomAbstractCls1]):  # [abstract-method,abstract-method]  # __iter__, __len__
    pass
class CustomImplementation(CustomAbstractCls2):  # [abstract-method,abstract-method]  # __iter__, __len__
    pass


# Type annotations
var_tuple: tuple[int, int]
var_dict: dict[int, str]
var_orderedDict: collections.OrderedDict[int, str]
var_container: collections.abc.Container[int]
var_sequence: collections.abc.Sequence[int]
var_iterable: collections.abc.Iterable[int]
var_awaitable: collections.abc.Awaitable[int]
var_contextmanager: contextlib.AbstractContextManager[int]
var_pattern: re.Pattern[int]
var_bytestring: collections.abc.ByteString
var_hashable: collections.abc.Hashable
var_sized: collections.abc.Sized

# Type annotation with unsubscriptable type
var_int: int[int]  # [unsubscriptable-object]
var_hashable2: collections.abc.Hashable[int]  # [unsubscriptable-object]
var_sized2: collections.abc.Sized[int]  # [unsubscriptable-object]

# subscriptable with Python 3.9
var_bytestring2: collections.abc.ByteString[int]