Skip to content

Commit 9454a60

Browse files
committed
Get rid of OrderedDict
1 parent 45a664d commit 9454a60

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
- (!) README.md
2-
- Do not use OrderedDict (dictionaries in Python 3.7 are now ordered)
32
- Docstrings
43
- Features
54
- Models layer

json_to_models/dynamic_typing/typing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import operator
2-
from collections import OrderedDict
32
from inspect import isclass
43
from typing import Dict, Set, Tuple
54

@@ -28,7 +27,7 @@ def compile_imports(imports: ImportPathList) -> str:
2827
"""
2928
Merge list of imports path and convert them into list code (string)
3029
"""
31-
class_imports_map: Dict[str, Set[str]] = OrderedDict()
30+
class_imports_map: Dict[str, Set[str]] = {}
3231
package_imports_set: Set[str] = set()
3332
for module, classes in filter(None, imports):
3433
if classes is None:
@@ -42,7 +41,7 @@ def compile_imports(imports: ImportPathList) -> str:
4241
class_imports_map[module] = classes_set
4342

4443
# Sort imports by package name and sort class names of each import
45-
class_imports_map = OrderedDict(sorted(
44+
class_imports_map = dict(sorted(
4645
((module, sorted(classes)) for module, classes in class_imports_map.items()),
4746
key=operator.itemgetter(0)
4847
))

json_to_models/generator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
from collections import OrderedDict
32
from typing import Any, Callable, List, Optional, Pattern, Union
43

54
from unidecode import unidecode
@@ -114,7 +113,7 @@ def merge_field_sets(self, field_sets: List[MetaData]) -> MetaData:
114113
"""
115114
Merge fields sets into one set of pairs (key, metadata)
116115
"""
117-
fields: dict = OrderedDict()
116+
fields: dict = {}
118117

119118
first = True
120119
for model in field_sets:
@@ -166,7 +165,7 @@ def optimize_type(self, meta: MetaData, process_model_ptr=False) -> MetaData:
166165
Default is False to prevent recursion cycles.
167166
"""
168167
if isinstance(meta, dict):
169-
fields = OrderedDict()
168+
fields = {}
170169

171170
for k, v in meta.items():
172171
fields[k] = self.optimize_type(v)

json_to_models/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import OrderedDict, defaultdict
1+
from collections import defaultdict
22
from itertools import chain, combinations
33
from typing import Dict, Iterable, List, Set, Tuple
44

@@ -50,7 +50,7 @@ def __init__(self, *models_cmp: ModelCmp):
5050
:param models_cmp: list of model comparators. If you want merge only equals models pass ModelFieldsEquals()
5151
"""
5252
self._models_cmp = models_cmp or self.DEFAULT_MODELS_CMP
53-
self._registry: Dict[str, ModelMeta] = OrderedDict()
53+
self._registry: Dict[str, ModelMeta] = {}
5454
self._index = Index()
5555

5656
@property

0 commit comments

Comments
 (0)