-
Notifications
You must be signed in to change notification settings - Fork 80
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
Manage optional field in Message body #579
Comments
my understanding is that for proto3, scalar non-repeated fields are not actually optional on the wire, nor on the generated class. IE - if you construct it with None, my understanding is that you will get the 0-value. mypy-protobuf/mypy_protobuf/main.py Line 439 in 7506de3
It's possible my understanding is wrong. I'd be welcome to a fix - as long as it includes a unit test that proves that this behavior is expected - eg mypy-protobuf/test/test_generated_mypy.py Line 421 in 7506de3
|
With the newest version of protobuf, it seems that it's possible to explicitly mark scalar fields as |
I made an error in my previous message
Actually, the fields are optional on the wire, however if you access them in the generated class, you will still get the 0-value. The behavior is documented here. https://protobuf.dev/reference/python/python-generated/#singular-fields-proto3 I was able to validate this with an improvement to the unit test in #655. You can check it out to prove the behavior returns the 0-value rather than |
Optional field are well manage in constructor but not in the class field declaration. I think it"s a quick fix to do in writeMessage as I can see but not sure. Today generation is:
But it must be:
The text was updated successfully, but these errors were encountered: