-
Notifications
You must be signed in to change notification settings - Fork 213
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
Implement Message.__bool__ #142
Conversation
This look interesting. I like the general idea for sure. Given proto's use of default zero values I wonder if it's more useful to know:
This PR seems to implement 1 unless I'm mistaken. Thoughts? To elaborate, you can see that a Python list will return to >>> test = []
>>> bool(test)
False
>>> test.append(1)
>>> bool(test)
True
>>> test.pop()
1
>>> bool(test)
False I think the proto equivalent is setting the |
Am I mistaken in thinking that returning self._serialized_on_wire would achieve this? |
I should have this working as a collection would now, so if a value is set to anything and then has its value set to its default it will return |
@Gobot1234 I think we can merge this in principal, but it's significant an API feature that it should really be documented. Would you mind? |
Ah yes of course. |
Sorry just realised I haven't added it to the Sphinx special members directive yet |
* Implement Message.__bool__ with similar semantics to a collection, such that any value being set on the message (i.e. having a non-default value) make the Message value truthy . Co-authored-by: nat <n@natn.me>
Carries on from #138, I messed up the git tree.