danielgtaylor / danielgtaylor/python-betterproto

`mypy --strict` fails with `Name "betterproto.ServiceStub" is not defined`

未关闭
#577 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug investigation needed
主要语言
Python
星标
1.8k
派生
234
PR 合并指标
30 天内没有已合并 PR

描述

### Summary

`mypy --strict` fails with `Name "betterproto.ServiceStub" is not defined`

### Reproduction Steps

1. Generate some gRPC files from some proto files
2. Run `mypy` on the generated code

### Expected Results

`mypy` passes.

### Actual Results

```
error: Name "betterproto.ServiceStub" is not defined [name-defined]
```

Where the stub class is defined in the generated code.

I see the symbol is imported in https://github.com/danielgtaylor/python-betterproto/blob/master/src/betterproto/__init__.py, but it seems like `mypy` needs imported symbols to be explicitly *exported*, probably via `__all__` or using `from x import y as y` (see https://peps.python.org/pep-0484/#stub-files).

### System Information

```console
$ protoc --version; python --version; pip show betterproto; pip show grpcio-tools
bash: protoc: command not found
Python 3.11.9
Name: betterproto
Version: 2.0.0b6
Location: /home/luca/devel/frequenz-microgrid-betterproto/.direnv/python-3.11.9/lib/python3.11/site-packages
Requires: grpclib, python-dateutil
Required-by: frequenz-microgrid-betterproto
Name: grpcio-tools
Version: 1.63.0
Location: /home/luca/devel/setuptools-betterproto/.direnv/python-3.11/lib/python3.11/site-packages
Requires: grpcio, protobuf, setuptools
```

(I'm using `grpcio-tools` to generate the files, not `protoc`)

### Checklist

- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.

贡献指南

打开贡献指南

调研方向

从 src/betterproto/__init__.py 开始,该文件中会导入 ServiceStub,并检查导出的符号是如何暴露给 mypy 的。通过生成 gRPC 文件并对生成的代码运行 mypy --strict 来复现该问题;当生成的代码不再报告 Name "betterproto.ServiceStub" is not defined 时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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