danielgtaylor / python-betterproto

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

Missing import in generated code when using well known types #552

Open 124C41p opened 11 months ago

124C41p commented 11 months ago

Summary

When compiling a proto file which references well known types, protoc should generate the line import betterproto.lib.google.protobuf as betterproto_lib_google_protobuf. This does not happen in the following edge case.

Reproduction Steps

Create a file foo.proto whith the following content

syntax = "proto3";
import "google/protobuf/empty.proto";

service foo {
    rpc foo (google.protobuf.Empty) returns (MyEmpty);
}

message MyEmpty {}

and compile it by running python -m grpc_tools.protoc -I . --python_betterproto_out=lib foo.proto.

Expected Results

The generated file __init__.py references a module betterproto_lib_google_protobuf, so it should import betterproto.lib.google.protobuf as betterproto_lib_google_protobuf.

Note that it actually would be imported if I had used google.protobuf.Empty as the return value of the RPC above.

Actual Results

The generated file __init__.py does not import betterproto.lib.google.protobuf as betterproto_lib_google_protobuf

System Information

libprotoc 25.0 Python 3.10.12 betterproto 2.0.0b6 (tested with released version and github master branch)

Checklist

yc2984 commented 10 months ago

related but not exactly the same: https://github.com/danielgtaylor/python-betterproto/issues/554