Skip to content

Commit bfd865b

Browse files
committed
Minor speed up
1 parent 03c912f commit bfd865b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

json_to_models/generator.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
StringSerializable, StringSerializableRegistry, Unknown, registry)
1010

1111
keywords_set = set(keyword.kwlist)
12-
12+
_static_types = {float, bool, int}
1313

1414
class MetadataGenerator:
1515
CONVERTER_TYPE = Optional[Callable[[str], Any]]
@@ -61,15 +61,12 @@ def _detect_type(self, value, convert_dict=True) -> MetaData:
6161
Converts json value to metadata
6262
"""
6363
# Simple types
64-
if isinstance(value, float):
65-
return float
66-
elif isinstance(value, bool):
67-
return bool
68-
elif isinstance(value, int):
69-
return int
64+
t = type(value)
65+
if t in _static_types:
66+
return t
7067

7168
# List trying to yield nested type
72-
elif isinstance(value, list):
69+
elif t is list:
7370
if value:
7471
types = [self._detect_type(item) for item in value]
7572
if len(types) > 1:

0 commit comments

Comments
 (0)