-
Notifications
You must be signed in to change notification settings - Fork 229
Implement Message.__bool__ #138
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
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 see how this can be convenient, and I guess this is idiomatic if we think of the message as being like a collection, which are typically falsey when empty in python.
Though I feel it's still a little bit of a weird thing to do conceptually, and as an API feature it's quite awkward to backtrack on, so I'm going to approve it with low confidence, and wait for a second opinion before merging.
Co-authored-by: nat <n@natn.me>
As things go I think it would be better if you could detect if any value was passed to init but I wasn't too sure how that could be implemented with dataclasses as, following on from the collections note, |
So the message is true if any of the fields are populated with a truthy value? |
If #130 was merged however this could be done |
I should have said this earlier, but an API change like this should really have a couple tests. |
…ive (danielgtaylor#102) Fixes danielgtaylor#93 to_dict returns wrong enum fields when numbering is not consecutive
- replace some usages of `==` with `is` - use available constants instead of magic strings for type names Co-authored-by: nat <nat.noordanus@gmail.com>
…ture to represent parsed data (danielgtaylor#121) Refactor plugin to parse input into data-class based hierarchical structure
* re-implement README gRPC client example to be a self-contained script - fix a syntax error - fix a usage error * asyncio.run() was added in 3.7 - this lib targets >= 3.6 * Apply suggestions from code review Optimized imports, store RPC call result before printing Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com> * add entry-point check to example Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
danielgtaylor#110) * Serialize default values in oneofs when calling to_dict() or to_json() This change is consistent with the official protobuf implementation. If a default value is set when using a oneof, and then a message is translated from message -> JSON -> message, the default value is kept in tact. Also, if no default value is set, they remain null. * Some cleanup + testing for nested messages with oneofs * Cleanup oneof_enum test cases, they should be fixed This _should_ address: danielgtaylor#63 * Include default value oneof fields when serializing to bytes This will cause oneof fields with default values to explicitly be sent to clients. Note that does not mean that all fields are serialized and sent to clients, just those that _could_ be null and are not. * Remove assignment when populating a sub-message within a proto Also, move setattr out one indentation level * Properly transform proto with empty string in oneof to bytes Also, updated tests to ensure that which_one_of picks up the set field * Formatting betterproto/__init__.py * Adding test cases demonstrating equivalent behaviour with google impl * Removing a temporary file I made locally * Adding some clarifying comments * Fixing tests for python38
* Fix static type checking in grpclib client * Fix python3.6 compatibility issue with dataclasses
- This update improves support for windows & removes the direct dependency on poetry
Use the standard library keyword module instead of a hard coded list and applying it to enum keys as well.
I think I'm gonna have to close and reopen this. |
This allows you to check if a message has had a non-default value set for it.
Proposed use case