danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.54k stars 216 forks source link

Support proto3 optional fields #563

Closed BaxHugh closed 8 months ago

BaxHugh commented 8 months ago

Summary

Compiling a proto file with optional fields gives 'protoc-gen-python_betterproto hasn't been updated to support optional fields in proto3'

What is the feature request for?

The core library

The Problem

My project requires optional fields, and the lack of support for optional fields is blocking us from using python-betterproto which would be very useful for our python documentation / intellisense.

Example proto file

has_optional.proto

syntax = "proto3";
package optional_fields_demo;

message HasOptionalPrimitives {
  optional int32 int32_field = 1;
  optional int64 int64_field = 2;
  optional uint32 uint32_field = 3;
}

Run the command

protoc -I . --python_betterproto_out=lib ./has_optional.proto

which returns

Writing __init__.py
Writing optional_fields_demo.py
has_optional.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-python_betterproto hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.
--python_betterproto_out: 

The Ideal Solution

Support proto3 optional fields.

The Current Solution

No response

BaxHugh commented 8 months ago

This issue has already been solved here: https://github.com/danielgtaylor/python-betterproto/issues/35. The registry mirror of my org was stopping me from getting the latest package version