danielgtaylor / danielgtaylor/python-betterproto
ImportError: cannot import name for ellipsis imports
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 234
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Setup:
```
❯ tree
.
├── Content.proto
├── Detection.proto
└── lib
1 directory, 2 files
```
Content.proto
```
syntax = "proto3";
package My.Content;
import "Detection.proto";
message Content {
enum Type {
TYPE_UNSPECIFIED = 0;
TYPE_VIDEO = 1;
}
Type type = 1;
My.Detection.Detection.Gender gender = 2;
}
```
Detection.proto
```
syntax = "proto3";
package My.Detection;
message Detection {
enum Gender {
GENDER_UNSPECIFIED = 0;
GENDER_FEMALE = 1;
GENDER_MALE = 2;
}
Gender gender = 1;
}
```
protoc:
```
❯ protoc -I . --python_betterproto_out=lib *.proto
❯ tail -n 2 lib/My/Content/__init__.py
from ... import MyContentContentType as __MyContentContentType__
from ... import MyDetectionDetectionGender as __MyDetectionDetectionGender__
```
Test:
```
❯ python3 265ms
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lib.My import Content
Traceback (most recent call last):
File "", line 1, in
File "/wa/qt/better/lib/My/Content/__init__.py", line 23, in
from ... import MyContentContentType as __MyContentContentType__
ImportError: cannot import name 'MyContentContentType'
>>>
```
This is a small example, I get a different error in my actual project, but I suspect it's related: `ValueError: attempted relative import beyond top-level package`. Shouldn't the import read something along the lines of:
```
from ..Content import ContentType as __MyContentContentType__
from ..Detection import DetectionGender as __MyDetectionDetectionGender__
```
Is this a know issue or am I doing something out of the ordinary? I am using the same proto files to generate C++ code.
コントリビューションガイド
調査の方向性
Reproduce the issue with Content.proto and Detection.proto using the shown protoc command, then inspect the generated lib/My/Content/__init__.py imports. Trace how the generator chooses relative-import levels for MyContentContentType and MyDetectionDetectionGender. Done means importing Content from lib.My succeeds without ImportError or an attempted relative import beyond the top-level package.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100