-
Notifications
You must be signed in to change notification settings - Fork 1
Allow Unset values to avoid being send during serialization #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ if {{ source }} is not None: | |
{% if property.required %} | ||
{{ destination }} = {{ source }} | ||
{% else %} | ||
{{ destination }} = {{ source }} if {{ source }} else None | ||
if {{ source }} is UNSET: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my context, where is the macro There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's called frequently in the various |
||
{{ destination }} = UNSET | ||
else: | ||
{{ destination }} = {{ source }} if {{ source }} else None | ||
{% endif %} | ||
{% endmacro %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ def _parse_{{ property.python_name }}(data: Dict[str, Any]) -> {{ property.get_t | |
{% if not property.required %} | ||
if {{ source }} is None: | ||
{{ destination }}: {{ property.get_type_string() }} = None | ||
elif {{ source }} is UNSET: | ||
{{ destination }} = UNSET | ||
{% endif %} | ||
{% for inner_property in property.inner_properties %} | ||
{% if loop.first and property.required %}{# No if None statement before this #} | ||
|
@@ -36,7 +38,7 @@ else: | |
{% endif %} | ||
{% if inner_property.template %} | ||
{% from "property_templates/" + inner_property.template import transform %} | ||
{{ transform(inner_property, source, destination) | indent(8) }} | ||
{{ transform(inner_property, source, destination) | indent(4) }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What caused this indentation level to change? |
||
{% else %} | ||
{{ destination }} = {{ source }} | ||
{% endif %} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that a property is both required AND unset, and if so is it desired that it would be exposed in the dictionary directly (instead of, say, erroring)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a property is required, we shouldn't allow unset - we simply shouldn't allow a default. It could still be nullable and required, in which case we should allow it to be
None
.