danielgtaylor / danielgtaylor/python-betterproto

Capitalized (Title case) package name causes invalid gRPC code generation

オープン
#272 コメント 0 件 リアクション 4 件 担当者 0 名 GitHub で見る
compiler-bug
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

Working with gRPC on `v2.0.0b3`, if the `.proto` package name starts with a capital letter, e.g.
``` proto
package Echo;
```
Then the generated file becomes significantly different and invalid. Most obviously there is `from .. import MessageName as _MessageName__` for the message types and it can't be imported.

For example, take the `echo.proto` example from the README.md and generate as suggested with `python -m grpc_tools.protoc -I . --python_betterproto_out=. echo.proto`, it seems fine, but edit it to `package Echo;` and in `Echo/__init__.py` you get, among other changes not limited to `s/echo/Echo`, at the end:

``` py
from .. import EchoEchoRequest as _EchoEchoRequest__
from .. import EchoEchoResponse as _EchoEchoResponse__
from .. import EchoEchoStreamResponse as _EchoEchoStreamResponse__
```

These don't exist, and the package can't be imported.

Found in `v2.0.0b3`. Thanks!

----
For completeness, here's the problematic `.proto`
``` proto
syntax = "proto3";

package Echo;

message EchoRequest {
string value = 1;
// Number of extra times to echo
uint32 extra_times = 2;
}

message EchoResponse {
repeated string values = 1;
}

message EchoStreamResponse {
string value = 1;
}

service Echo {
rpc Echo(EchoRequest) returns (EchoResponse);
rpc EchoStream(EchoRequest) returns (stream EchoStreamResponse);
}
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

README.md の echo.proto の例から始め、package を Echo に変更した後、記載されている python -m grpc_tools.protoc コマンドを使って問題を再現します。生成された Echo/__init__.py を調べ、特に報告に示されている imports を確認します。大文字で始まる package の出力を import でき、生成された message 参照が正しく解決されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
grpc, python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。