Skip to content

Commit 025fada

Browse files
committed
fix
1 parent 00f8624 commit 025fada

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/normalize_json/normalize.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ def check_types(node: Node, value: typing.Any, modifiers: list[Modifier]):
106106
if node.get('array') \
107107
else value.__class__.__name__
108108

109-
vexpected = TYPE_MAPPING.get(node.get('type', 'string'))
109+
node_type = node.get('type', 'string')
110+
111+
vexpected = TYPE_MAPPING.get(node_type)
110112
if actual == vexpected \
111113
or (actual == 'int' and vexpected in ['number', 'float']) \
112114
or (actual == 'NoneType' and 'default_null' in modifiers):
113115
return None
114116

115-
return actual, node['type']
117+
return actual, node_type
116118

117119
def handle_modifiers(node: Node, mapped_name: str, modifiers: list[Modifier], old_value: typing.Any):
118120
value = old_value
@@ -135,7 +137,7 @@ def handle_modifiers(node: Node, mapped_name: str, modifiers: list[Modifier], ol
135137
value = value.split(pick)[0]
136138

137139
if 'enforce' in modifiers and check_types(node, value, modifiers):
138-
match node['type']:
140+
match node.get('type', 'string'):
139141
case 'number':
140142
value = re.sub(r'[^0-9\.]', '', value) or 0
141143
value = float(value)

0 commit comments

Comments
 (0)