2
2
def _parse_ {{ property .python_name }}(data : Any ) - > {{ property .get_type_string () }}:
3
3
data = None if isinstance (data , Unset ) else data
4
4
{{ property .python_name }}: {{ property .get_type_string () }}
5
- {% for inner_property in property .inner_properties % }
6
- {% if inner_property . template and not loop .last % }
5
+ {% for inner_property in property .inner_properties_with_template % }
6
+ {% if not loop .last or property . inner_properties_without_template % }
7
7
try :
8
8
{% from "property_templates/" + inner_property .template import construct % }
9
9
{{ construct (inner_property , "data" , initial_value = "UNSET" ) | indent (8 ) }}
10
10
return {{ property .python_name }}
11
11
except : # noqa: E722
12
12
pass
13
- {% elif inner_property . template and loop . last % }{# Don't do try/except for the last one #}
13
+ {% else % }{# Don't do try/except for the last one #}
14
14
{% from "property_templates/" + inner_property .template import construct % }
15
15
{{ construct (inner_property , "data" , initial_value = "UNSET" ) | indent (4 ) }}
16
16
return {{ property .python_name }}
17
- {% else % }
18
- return cast ({{ inner_property .get_type_string () }}, data )
19
17
{% endif % }
20
18
{% endfor % }
19
+ {% if property .inner_properties_without_template % }
20
+ {# Doesn't really matter what we cast it to as this type will be erased, so cast to one of the options #}
21
+ return cast ({{ property .inner_properties_without_template [0 ].get_type_string () }}, data )
22
+ {% endif % }
21
23
22
24
{{ property .python_name }} = _parse_ {{ property .python_name }}({{ source }})
23
25
{% endmacro % }
@@ -37,19 +39,22 @@ elif {{ source }} is None:
37
39
{% endif % }
38
40
{{ destination }}{% if declare_type % }: {{ property .get_type_string () }}{% endif % } = None
39
41
{% endif % }
40
- {% for inner_property in property .inner_properties % }
42
+ {% for inner_property in property .inner_properties_with_template % }
41
43
{% if loop .first and property .required and not property .nullable % }{# No if UNSET or if None statement before this #}
42
44
if isinstance ({{ source }}, {{ inner_property .get_instance_type_string () }}):
43
- {% elif not loop .last % }
45
+ {% elif not loop .last or property . inner_properties_without_template % }
44
46
elif isinstance ({{ source }}, {{ inner_property .get_instance_type_string () }}):
45
47
{% else % }
46
48
else :
47
49
{% endif % }
48
- {% if inner_property .template % }
49
50
{% from "property_templates/" + inner_property .template import transform % }
50
51
{{ transform (inner_property , source , destination , declare_type = False ) | indent (4 ) }}
51
- {% else % }
52
+ {% endfor % }
53
+ {% if property .inner_properties_without_template and (property .inner_properties_with_template or not property .required )% }
54
+ else :
52
55
{{ destination }} = {{ source }}
56
+ {% elif property .inner_properties_without_template % }
57
+ {{ destination }} = {{ source }}
53
58
{% endif % }
54
- { % endfor % }
59
+
55
60
{% endmacro % }
0 commit comments