@@ -9,20 +9,21 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri
9
9
return data
10
10
{% endif %}
11
11
{% for inner_property in property .inner_properties_with_template () %}
12
- {% if not loop .last or property .has_properties_without_templates %}
12
+ {% import "property_templates/" + inner_property .template as inner_template %}
13
+ {% if inner_template .check_type_for_construct and (not loop .last or property .has_properties_without_templates ) %}
13
14
try:
14
- {% from "property_templates/" + inner_property .template import construct , check_type_for_construct %}
15
- if not {{ check_type_for_construct(inner_property, "data") }}:
15
+ if not {{ inner_template.check_type_for_construct(inner_property, "data") }}:
16
16
raise TypeError()
17
- {{ construct(inner_property, "data", initial_value="UNSET") | indent(8) }}
17
+ {{ inner_template. construct(inner_property, "data", initial_value="UNSET") | indent(8) }}
18
18
return {{ inner_property.python_name }}
19
19
except: # noqa: E722
20
20
pass
21
- {% else %} {# Don't do try/except for the last one #}
22
- {% from "property_templates/" + inner_property . template import construct , check_type_for_construct %}
23
- if not {{ check_type_for_construct(inner_property, "data") }}:
21
+ {% else %} {# Don't do try/except for the last one nor any properties with no type checking #}
22
+ {% if inner_template . check_type_for_construct %}
23
+ if not {{ inner_template. check_type_for_construct(inner_property, "data") }}:
24
24
raise TypeError()
25
- {{ construct(inner_property, "data", initial_value="UNSET") | indent(4) }}
25
+ {% endif %}
26
+ {{ inner_template.construct(inner_property, "data", initial_value="UNSET") | indent(4) }}
26
27
return {{ inner_property.python_name }}
27
28
{% endif %}
28
29
{% endfor %}
@@ -34,9 +35,6 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri
34
35
{{ property.python_name }} = _parse_{{ property.python_name }}({{ source }})
35
36
{% endmacro %}
36
37
37
- {# For now we assume there will be no unions of unions #}
38
- {% macro check_type_for_construct (property , source ) %} True{% endmacro %}
39
-
40
38
{% macro transform (property , source , destination , declare_type =True , stringify =False ) %}
41
39
{% if not property .required or property .nullable %}
42
40
{{ destination }}{% if declare_type %} : {{ property.get_type_string(json=True) }}{% endif %}
0 commit comments