-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake8_typing_imports.py
628 lines (588 loc) · 30.9 KB
/
flake8_typing_imports.py
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
import ast
import collections
import configparser
import os.path
import sys
from typing import Any
from typing import Dict
from typing import Generator
from typing import List
from typing import NamedTuple
from typing import Set
from typing import Tuple
from typing import Type
if sys.version_info < (3, 8): # pragma: no cover (<PY38)
import importlib_metadata
else: # pragma: no cover (PY38+)
import importlib.metadata as importlib_metadata
class Version(NamedTuple):
major: int
minor: int
patch: int
def Version_str(self: Version) -> str:
return f'{self.major}.{self.minor}.{self.patch}'
def Version_new(major: int = 0, minor: int = 0, patch: int = 0) -> Version:
return Version(major, minor, patch)
def Version_parse(s: str) -> Version:
return Version_new(*[int(p) for p in s.split('.')])
# GENERATED BY ./bin/build-generated
SYMBOLS = (
(
Version(3, 5, 0), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'BinaryIO', 'ByteString',
'Callable', 'Container', 'Dict', 'FrozenSet', 'Generator',
'Generic', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator',
'KeysView', 'List', 'Mapping', 'MappingView', 'Match',
'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple',
'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TextIO', 'Tuple', 'TypeVar',
'Union', 'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 5, 1), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'BinaryIO', 'ByteString',
'Callable', 'Container', 'Dict', 'FrozenSet', 'Generator',
'Generic', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator',
'KeysView', 'List', 'Mapping', 'MappingView', 'Match',
'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple',
'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TextIO', 'Tuple', 'TypeVar',
'Union', 'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 5, 2), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncIterable', 'AsyncIterator',
'Awaitable', 'BinaryIO', 'ByteString', 'Callable', 'Container',
'DefaultDict', 'Dict', 'FrozenSet', 'Generator', 'Generic',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO',
'Tuple', 'Type', 'TypeVar', 'Union', 'ValuesView', 'cast',
'get_type_hints', 'no_type_check', 'no_type_check_decorator',
'overload',
)),
),
(
Version(3, 5, 3), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncIterable', 'AsyncIterator',
'Awaitable', 'BinaryIO', 'ByteString', 'Callable', 'ClassVar',
'Container', 'Coroutine', 'DefaultDict', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView', 'Iterable',
'Iterator', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match',
'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple',
'NewType', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set',
'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex',
'SupportsFloat', 'SupportsInt', 'SupportsRound', 'TYPE_CHECKING',
'Text', 'TextIO', 'Tuple', 'Type', 'TypeVar', 'Union',
'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 5, 4), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO',
'ByteString', 'Callable', 'ChainMap', 'ClassVar', 'Container',
'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque',
'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'NoReturn', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set',
'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex',
'SupportsFloat', 'SupportsInt', 'SupportsRound', 'TYPE_CHECKING',
'Text', 'TextIO', 'Tuple', 'Type', 'TypeVar', 'Union',
'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 5, 5), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO',
'ByteString', 'Callable', 'ChainMap', 'ClassVar', 'Container',
'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque',
'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'NoReturn', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set',
'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex',
'SupportsFloat', 'SupportsInt', 'SupportsRound', 'TYPE_CHECKING',
'Text', 'TextIO', 'Tuple', 'Type', 'TypeVar', 'Union',
'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 5, 6), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO',
'ByteString', 'Callable', 'ChainMap', 'ClassVar', 'Container',
'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque',
'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'NoReturn', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set',
'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex',
'SupportsFloat', 'SupportsInt', 'SupportsRound', 'TYPE_CHECKING',
'Text', 'TextIO', 'Tuple', 'Type', 'TypeVar', 'Union',
'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 5, 7), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO',
'ByteString', 'Callable', 'ChainMap', 'ClassVar', 'Container',
'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque',
'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'NoReturn', 'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set',
'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex',
'SupportsFloat', 'SupportsInt', 'SupportsRound', 'TYPE_CHECKING',
'Text', 'TextIO', 'Tuple', 'Type', 'TypeVar', 'Union',
'ValuesView', 'cast', 'get_type_hints', 'no_type_check',
'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 0), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncIterable', 'AsyncIterator',
'Awaitable', 'BinaryIO', 'ByteString', 'Callable', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'DefaultDict', 'Dict', 'FrozenSet', 'Generator', 'Generic',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO',
'Tuple', 'Type', 'TypeVar', 'Union', 'ValuesView', 'cast',
'get_type_hints', 'no_type_check', 'no_type_check_decorator',
'overload',
)),
),
(
Version(3, 6, 1), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncGenerator', 'AsyncIterable',
'AsyncIterator', 'Awaitable', 'BinaryIO', 'ByteString', 'Callable',
'ChainMap', 'ClassVar', 'Collection', 'Container',
'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque',
'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta',
'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KeysView',
'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping',
'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType',
'Optional', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO',
'Tuple', 'Type', 'TypeVar', 'Union', 'ValuesView', 'cast',
'get_type_hints', 'no_type_check', 'no_type_check_decorator',
'overload',
)),
),
(
Version(3, 6, 2), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 3), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 4), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 5), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 6), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 7), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 8), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 6, 9), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet',
'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO',
'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 7, 0), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'ForwardRef',
'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView',
'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 7, 1), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'ForwardRef',
'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView',
'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs',
'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt',
'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO', 'Tuple',
'Type', 'TypeVar', 'Union', 'ValuesView', 'cast', 'get_type_hints',
'no_type_check', 'no_type_check_decorator', 'overload',
)),
),
(
Version(3, 7, 2), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'ForwardRef',
'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView',
'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'OrderedDict', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO',
'Tuple', 'Type', 'TypeVar', 'Union', 'ValuesView', 'cast',
'get_type_hints', 'no_type_check', 'no_type_check_decorator',
'overload',
)),
),
(
Version(3, 7, 3), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'ForwardRef',
'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView',
'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'OrderedDict', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO',
'Tuple', 'Type', 'TypeVar', 'Union', 'ValuesView', 'cast',
'get_type_hints', 'no_type_check', 'no_type_check_decorator',
'overload',
)),
),
(
Version(3, 7, 4), frozenset((
'AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager',
'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable',
'BinaryIO', 'ByteString', 'Callable', 'ChainMap', 'ClassVar',
'Collection', 'Container', 'ContextManager', 'Coroutine',
'Counter', 'DefaultDict', 'Deque', 'Dict', 'ForwardRef',
'FrozenSet', 'Generator', 'Generic', 'Hashable', 'IO', 'ItemsView',
'Iterable', 'Iterator', 'KeysView', 'List', 'Mapping',
'MappingView', 'Match', 'MutableMapping', 'MutableSequence',
'MutableSet', 'NamedTuple', 'NewType', 'NoReturn', 'Optional',
'OrderedDict', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized',
'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat',
'SupportsInt', 'SupportsRound', 'TYPE_CHECKING', 'Text', 'TextIO',
'Tuple', 'Type', 'TypeVar', 'Union', 'ValuesView', 'cast',
'get_type_hints', 'no_type_check', 'no_type_check_decorator',
'overload',
)),
),
)
# END GENERATED
VERSIONS = frozenset(version for version, _ in SYMBOLS)
class Visitor(ast.NodeVisitor):
def __init__(self) -> None:
self._level = -1
self.imports: Dict[str, List[Tuple[int, int]]]
self.imports = collections.defaultdict(list)
self.defined_overload = False
self.unions_pattern_or_match: List[Tuple[int, int]] = []
self.from_imported_names: Set[str] = set()
self._in_namedtuple = False
self.namedtuple_methods: List[Tuple[int, int]] = []
self.namedtuple_defaults: List[Tuple[int, int]] = []
def _is_typing(self, node: ast.AST, names: Tuple[str, ...]) -> bool:
return (
isinstance(node, ast.Name) and
node.id in names and
node.id in self.from_imported_names
) or (
isinstance(node, ast.Attribute) and
isinstance(node.value, ast.Name) and
node.value.id == 'typing' and
node.attr in names
)
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
if node.level == 0 and node.module == 'typing' and self._level == 0:
for name in node.names:
self.imports[name.name].append((node.lineno, node.col_offset))
if not name.asname:
self.from_imported_names.add(name.name)
self.generic_visit(node)
def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
if self._level == 1 and node.name == 'overload':
self.defined_overload = True
if self._in_namedtuple:
self.namedtuple_methods.append((node.lineno, node.col_offset))
self.generic_visit(node)
def visit_Subscript(self, node: ast.Subscript) -> None:
if (
self._is_typing(node.value, ('Union',)) and
isinstance(node.slice, ast.Index) and
isinstance(node.slice.value, ast.Tuple) and
len(node.slice.value.elts) > 1 and
any(
self._is_typing(x, ('Pattern', 'Match'))
for x in node.slice.value.elts
)
):
self.unions_pattern_or_match.append((node.lineno, node.col_offset))
self.generic_visit(node)
def visit_ClassDef(self, node: ast.ClassDef) -> None:
if any(self._is_typing(base, ('NamedTuple',)) for base in node.bases):
self._in_namedtuple = True
try:
self.generic_visit(node)
finally:
self._in_namedtuple = False
else:
self.generic_visit(node)
def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
if self._in_namedtuple and node.value is not None:
self.namedtuple_defaults.append((node.lineno, node.col_offset))
self.generic_visit(node)
def generic_visit(self, node: ast.AST) -> None:
self._level += 1
super().generic_visit(node)
self._level -= 1
class Plugin:
name = __name__
version = importlib_metadata.version(__name__)
_min_python_version = Version(3, 5, 0)
@staticmethod
def add_options(option_manager: Any) -> None:
option_manager.add_option(
'--min-python-version', type='str', metavar='VERSION',
default='3.5.0', parse_from_config=True,
help=(
'Minimum version of python your code supports, '
'(default: %(default)s)'
),
)
@classmethod
def parse_options(cls, options: Any) -> None:
cfg = configparser.ConfigParser()
cfg.add_section('options')
cfg['options']['python_requires'] = f'>={options.min_python_version}'
if os.path.exists('setup.cfg'):
cfg.read('setup.cfg')
v = cls._min_python_version
for part in cfg['options']['python_requires'].split(','):
part = part.strip()
if part.startswith('>='):
v = Version_parse(part[2:])
v = max(v, SYMBOLS[0][0])
if v not in VERSIONS:
v_s = Version_str(v)
raise ValueError(f'min-python-version ({v_s}): unknown version')
cls._min_python_version = v
def __init__(self, tree: ast.AST):
self._tree = tree
def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
visitor = Visitor()
visitor.visit(self._tree)
if self._min_python_version < Version(3, 5, 2):
guard = '`if False: # TYPE_CHECKING`'
else:
guard = '`if TYPE_CHECKING:`'
msg = f'TYP001 guard import by {guard}: {{}} (not in {{}})'
error_versions: Dict[Tuple[int, int, str], List[Version]]
error_versions = collections.defaultdict(list)
for version, symbols in SYMBOLS:
if version < self._min_python_version:
continue
for k in set(visitor.imports) - symbols:
for line, col in visitor.imports[k]:
error_versions[(line, col, k)].append(version)
for (line, col, k), versions in error_versions.items():
versions_s = ', '.join(Version_str(v) for v in versions)
yield line, col, msg.format(k, versions_s), type(self)
msg = (
'TYP002 @overload is broken in <3.5.2, '
'add `if sys.version_info < (3, 5, 2): def overload(f): return f`'
)
if (
self._min_python_version < Version(3, 5, 2) and
'overload' in visitor.imports and
not visitor.defined_overload
):
for line, col in visitor.imports['overload']:
yield line, col, msg, type(self)
msg = (
'TYP003 Union[Match, ...] or Union[Pattern, ...] '
'must be quoted in <3.5.2'
)
if (
self._min_python_version < Version(3, 5, 2) and
visitor.unions_pattern_or_match
):
for line, col in visitor.unions_pattern_or_match:
yield line, col, msg, type(self)
msg = 'TYP004 NamedTuple does not support methods in 3.6.0'
if (
self._min_python_version < Version(3, 6, 1) and
visitor.namedtuple_methods
):
for line, col in visitor.namedtuple_methods:
yield line, col, msg, type(self)
msg = 'TYP005 NamedTuple does not support defaults in 3.6.0'
if (
self._min_python_version < Version(3, 6, 1) and
visitor.namedtuple_defaults
):
for line, col in visitor.namedtuple_defaults:
yield line, col, msg, type(self)