-
Notifications
You must be signed in to change notification settings - Fork 218
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
to_dict on empty nested types #200
base: master
Are you sure you want to change the base?
Changes from 2 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 |
---|---|---|
|
@@ -589,9 +589,8 @@ def __getattribute__(self, name: str) -> Any: | |
value = super().__getattribute__(name) | ||
if value is not PLACEHOLDER: | ||
return value | ||
|
||
value = self._get_field_default(name) | ||
super().__setattr__(name, value) | ||
return value | ||
|
||
def __setattr__(self, attr: str, value: Any) -> None: | ||
|
@@ -875,6 +874,10 @@ def parse(self: T, data: bytes) -> T: | |
) | ||
|
||
current = getattr(self, field_name) | ||
|
||
if self.__raw_get(field_name) == PLACEHOLDER: | ||
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. This should use 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. And maybe there should be a return on this 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. Why should there be a return here? The for loop has to continue 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. Sorry I meant continue |
||
setattr(self, field_name, current) | ||
|
||
if meta.proto_type == TYPE_MAP: | ||
# Value represents a single key/value pair entry in the map. | ||
current[value.key] = value.value | ||
|
@@ -972,6 +975,8 @@ def to_dict( | |
) | ||
): | ||
output[cased_name] = value.to_dict(casing, include_default_values) | ||
elif self.__raw_get(field_name) != PLACEHOLDER: | ||
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. Similar thing here, should be 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. I was thinking about that but I saw line 540 doing the same comparison |
||
output[cased_name] = {} | ||
elif meta.proto_type == TYPE_MAP: | ||
for k in value: | ||
if hasattr(value[k], "to_dict"): | ||
|
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.
This should be moved below that if statement
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.
The line 879 uses the
current
attribute, so putting that below doesn't make any sense