I would like to generate Python codes for protocol...
# general
I would like to generate Python codes for protocol buffer in version 3 with optional fields like following. Protobuf >= 3.15 supports
keyword, so it should be compiled successfully (I already tried on protoc >= 3.15 and checked that it was compiled without errors)
Copy code
syntax = "proto3";

package testing;

message SomeRequest {
  string required_field = 1;
  optional int32 optional_field;
However, when I execute
./pantsexport-codegen ::
, it said
Explicit 'optional' labels are disallowed in the Proto3 syntax. To define 'optional' fields in Proto3, simply remove the 'optional' label, as fields are 'optional' by default.
. How to resolve it ?
Detailed settings are below.
Copy code
Pants 2.11.0
Copy code
pants_version = "2.11.0"
backend_packages.add = [

interpreter_constraints = [">=3.9,<3.11"]

interpreter_constraints = [">=3.9,<3.11"]
version = "poetry>=1.1.12,<1.2"

mypy_plugin = true
infer_runtime_dependency = false
You’ll want to tweak these options to select your protoc version to use: https://www.pantsbuild.org/docs/reference-protoc
Or, if you use pants 2.12.x, then the default protoc version is already 3.20.1, so should be OK out of the box.
(in pants 2.11 the default protoc version is 3.11.4)
Thanks, I’ll try the option.
👍 1