-
Notifications
You must be signed in to change notification settings - Fork 220
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
Remove placeholders #641
base: master
Are you sure you want to change the base?
Remove placeholders #641
Conversation
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.
I do like this after more thought. Really do wish that PEP 505 happened
Thanks! I applied your suggestions |
"group", | ||
"oneof_index", | ||
) | ||
# TODO patch again to make field optional |
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 this no longer required?
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.
I let them for now as a reminder to change something else, but I'll remove it soon (in the fork)
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.
(done)
Note: I already merged this PR in the forked repo https://github.com/betterproto as discussed on Discord, so it's probably not worth it to solve the merge conflicts here |
Summary
Hello!
This is a first step in removing the
PLACEHOLDER
mechanism to greatly improve performance, make the whole code more Pythonic and simple and resolve a lot of bug. The motivation is more deeply described in #631This PR completely removes placeholder values from messages. Instead, fields are always set with there default value (empty string, 0,
None
for optional, members of a oneof and messages, ...). Therefore, all the message field are marked as optional and can be set to None, which is coherent with the specification (see the issue).As a consequence, this fixes the following issues:
Before merging it, I think it would be good to finish the work in progress (at least my other PR and another fix of the generation of the comments), and release a new version with all the recent bugfixes.
Performance
These changes also make it possible to remove the
__getattribute__
from messages. As expected, this has a great impact on the performance.With the following messages:
The following code takes 3.24s on my computer with the original (
master
) implementation with the Rust codec, and only 2s with my PR (without the Rust codec). Thus, even if the Rust codec is not supported for now, it is not a problem since the performance are better anyway.Breaking changes
This PR introduces two small breaking changes:
None
as value andgetattribute
is no longer defined.serialized_on_wire
function is now removed, since messages that were not serialized on the wire are now represented asNone
values. This function didn't really make sense in the first place imo, since being serialized is a property of a field of a message, not a property of a message itself (google's version hasHasField
, which indeed takes the field as a parameter).Checklist