danielgtaylor / danielgtaylor/python-betterproto

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

Open
#272 0 comments 4 reactions 0 assignees View on GitHub
compiler-bug
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

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);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.