danielgtaylor / danielgtaylor/python-betterproto

Missing import in generated code when using well known types

未关闭
#552 1 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug investigation needed
主要语言
Python
星标
1.8k
派生
234
PR 合并指标
30 天内没有已合并 PR

描述

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
  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 foo.proto 和所述的 python -m grpc_tools.protoc 命令复现问题,然后检查生成的 init.py。比较将 google.protobuf.Empty 用作 RPC 返回值时的输出。当边界情况的输出在所引用的别名下导入 betterproto.lib.google.protobuf,且生成的代码能够成功编译时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。