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
|
from __future__ import annotations
import sys
from collections import abc, defaultdict, deque
from random import Random
from typing import (
DefaultDict,
Deque,
Dict,
FrozenSet,
Iterable,
List,
Mapping,
Sequence,
Set,
Tuple,
Union,
)
try:
from types import UnionType
except ImportError:
UnionType = Union # type: ignore[misc,assignment]
PY_38 = sys.version_info.major == 3 and sys.version_info.minor == 8 # noqa: PLR2004
# Mapping of type annotations into concrete types. This is used to normalize python <= 3.9 annotations.
INSTANTIABLE_TYPE_MAPPING = {
DefaultDict: defaultdict,
Deque: deque,
Dict: dict,
FrozenSet: frozenset,
Iterable: list,
List: list,
Mapping: dict,
Sequence: list,
Set: set,
Tuple: tuple,
abc.Iterable: list,
abc.Mapping: dict,
abc.Sequence: list,
abc.Set: set,
UnionType: Union,
}
if not PY_38:
TYPE_MAPPING = INSTANTIABLE_TYPE_MAPPING
else:
# For 3.8, we have to keep the types from typing since dict[str] syntax is not supported in 3.8.
TYPE_MAPPING = {
DefaultDict: DefaultDict,
Deque: Deque,
Dict: Dict,
FrozenSet: FrozenSet,
Iterable: List,
List: List,
Mapping: Dict,
Sequence: List,
Set: Set,
Tuple: Tuple,
abc.Iterable: List,
abc.Mapping: Dict,
abc.Sequence: List,
abc.Set: Set,
}
DEFAULT_RANDOM = Random()
RANDOMIZE_COLLECTION_LENGTH = False
MIN_COLLECTION_LENGTH = 0
MAX_COLLECTION_LENGTH = 5
|