summaryrefslogtreecommitdiff
path: root/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.py
blob: 5ded73b3dd949ce3f2ec550ed7cd5feb02f058cf (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
"""Test generic alias support for stdlib types (added in PY39).

In type annotation context, they can be used with postponed evaluation enabled,
starting with PY37.
"""
# flake8: noqa
# pylint: disable=missing-docstring,pointless-statement
# pylint: disable=too-few-public-methods,multiple-statements,line-too-long
from __future__ import annotations

import abc
import collections
import collections.abc
import contextlib
import re


# ----- unsubscriptable (even with postponed evaluation) -----
# special
tuple[int, int]  # [unsubscriptable-object]
type[int]  # [unsubscriptable-object]
collections.abc.Callable[[int], str]  # [unsubscriptable-object]

# builtins
dict[int, str]  # [unsubscriptable-object]
list[int]  # [unsubscriptable-object]
set[int]  # [unsubscriptable-object]
frozenset[int]  # [unsubscriptable-object]

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

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

collections.abc.Iterable[int]  # [unsubscriptable-object]
collections.abc.Iterator[int]  # [unsubscriptable-object]
collections.abc.Generator[int, None, None]  # [unsubscriptable-object]
collections.abc.Reversible[int]  # [unsubscriptable-object]

collections.abc.Coroutine[list[str], str, int]  # [unsubscriptable-object,unsubscriptable-object]
collections.abc.AsyncGenerator[int, None]  # [unsubscriptable-object]
collections.abc.AsyncIterable[int]  # [unsubscriptable-object]
collections.abc.AsyncIterator[int]  # [unsubscriptable-object]
collections.abc.Awaitable[int]  # [unsubscriptable-object]

# contextlib
contextlib.AbstractContextManager[int]  # [unsubscriptable-object]
contextlib.AbstractAsyncContextManager[int]  # [unsubscriptable-object]

# re
re.Pattern[str]  # [unsubscriptable-object]
re.Match[str]  # [unsubscriptable-object]


# 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]  # [unsubscriptable-object]


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

class DerivedIterable(collections.abc.Iterable[int]):  # [unsubscriptable-object]
    pass

class DerivedCollection(collections.abc.Collection[int]):  # [unsubscriptable-object]
    pass


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

class DerivedSet(set[int]):  # [unsubscriptable-object]
    pass

class DerivedOrderedDict(collections.OrderedDict[int, str]):  # [unsubscriptable-object]
    pass

class DerivedListIterable(list[collections.abc.Iterable[int]]):  # [unsubscriptable-object,unsubscriptable-object]
    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,unsubscriptable-object]  # __len__
    pass
class CustomImplementation(CustomAbstractCls2):  # [abstract-method]  # __len__
    pass



# ----- subscriptable (with postponed evaluation) -----
# special
var_tuple: tuple[int, int]
var_type: type[int]
var_callable: collections.abc.Callable[[int], str]

# builtins
var_dict: dict[int, str]
var_list: list[int]
var_set: set[int]
var_frozenset: frozenset[int]

# collections
var_defaultdict: collections.defaultdict[int, str]
var_OrderedDict: collections.OrderedDict[int, str]
var_ChainMap: collections.ChainMap[int, str]
var_Counter: collections.Counter[int]
var_deque: collections.deque[int]

# collections.abc
var_abc_set: collections.abc.Set[int]
var_abc_collection: collections.abc.Collection[int]
var_abc_container: collections.abc.Container[int]
var_abc_ItemsView: collections.abc.ItemsView[int, str]
var_abc_KeysView: collections.abc.KeysView[int]
var_abc_Mapping: collections.abc.Mapping[int, str]
var_abc_MappingView: collections.abc.MappingView[int]
var_abc_MutableMapping: collections.abc.MutableMapping[int, str]
var_abc_MutableSequence: collections.abc.MutableSequence[int]
var_abc_MutableSet: collections.abc.MutableSet[int]
var_abc_Sequence: collections.abc.Sequence[int]
var_abc_ValuesView: collections.abc.ValuesView[int]

var_abc_Iterable: collections.abc.Iterable[int]
var_abc_Iterator: collections.abc.Iterator[int]
var_abc_Generator: collections.abc.Generator[int, None, None]
var_abc_Reversible: collections.abc.Reversible[int]

var_abc_Coroutine: collections.abc.Coroutine[list[str], str, int]
var_abc_AsyncGenerator: collections.abc.AsyncGenerator[int, None]
var_abc_AsyncIterable: collections.abc.AsyncIterable[int]
var_abc_AsyncIterator: collections.abc.AsyncIterator[int]
var_abc_Awaitable: collections.abc.Awaitable[int]

# contextlib
var_ContextManager: contextlib.AbstractContextManager[int]
var_AsyncContextManager: contextlib.AbstractAsyncContextManager[int]

# re
var_re_Pattern: re.Pattern[str]
var_re_Match: re.Match[str]


# unsubscriptable types
var_abc_Hashable: collections.abc.Hashable
var_abc_Sized: collections.abc.Sized
var_abc_Hashable2: collections.abc.Hashable[int]  # [unsubscriptable-object]
var_abc_Sized2: collections.abc.Sized[int]  # [unsubscriptable-object]

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