danielgtaylor / danielgtaylor/python-betterproto

ImportError: cannot import name for ellipsis imports

Open
#178 7 comments 3 reactions 0 assignees View on GitHub
investigation needed
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

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.

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.