-
Notifications
You must be signed in to change notification settings - Fork 81
Add support for optional proto3 fields #157
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
Add support for optional proto3 fields #157
Conversation
Hi! This looks great. Thank you for writing this up! It appears to fail the mypy build because typeshed has some very old plugin.proto autogenerated pyi definitions. For now, feel free to do a Also, if you have time, it'd be appreciated if you could add. If not, no worry, I can do it later. |
553b8c3
to
fda51d9
Compare
Hi - tests are still not passing here. You can run the tests locally with The local test runner also runs mypy - so it should validate that things are working. |
looks like the expected negative results have updated - so you can take a look at those by running |
From my quick readthrough of the errors - the "expected negative result" test files have updated, because the expected error message from mypy has changed - since for some cases the error message says something of the form "Expected a Union[a,b,c]" and w/ your change, that union has more members. I think if you run |
Unfortunately I've been having some trouble running the tests locally, I get errors like I'll try copying over the output from the diff on Travis to see if I can get the tests to pass there |
Ah that's unfortunate. I'd like to make the dev environment work nicely for everyone - so if you're willing, I'd like to try and get it working for you. If not, no worry - I can pick up the diff from you and complete it. I recognize some of those errors. Can you try these steps one by one and see and let me know which one (if any) fixes your dev environment issue. If we can isolate the issue, we can put some kind of check in to make sure the environment is set up consistently.
If nothing works, can you paste the entire output of the This diff is great, and I'm sorry you're running into issues getting the tests to pass. I've tried to make the environment consistent (run mypy on a pinned version in a virtual env, confirm version of protoc, etc), but it's a tough task, so want to fix things as they come up. I really hope we can get it up and running for you. |
Looks like your strategy of copying the output on travis worked - so I'll merge it! I'm still interested in helping debug your developer environment so we can avoid others running into the issue you had (if you have time). I'd also totally understand if not. Thank you for the contribution! |
|
Nice - I bet we can solve this issue for everyone by cleaning the generated/ directory every time - that directory isn't compiled incrementally, so it's at no cost to just do that, and should avoid this class of issues! |
This adds support for optional proto3 fields, introduced as an experimental feature in 3.12. The only really noticeable difference in the API is that since they track field presence they can be used in
HasFields
, so besides declaring support for the feature the only change is allowing fields withproto3_optional
set toTrue
inHasFields
.Closes #146
See https://github.com/protocolbuffers/protobuf/blob/v3.12.0/docs/field_presence.md and https://github.com/protocolbuffers/protobuf/blob/v3.12.0/docs/implementing_proto3_presence.md for more info.
Note that some changes were required for the protobuf types in typeshed: python/typeshed#4680
While it's merged, it hasn't made its way into the stubs bundled with mypy yet.