danielgtaylor / danielgtaylor/python-betterproto

ImportError: cannot import name for ellipsis imports

Aperta
#178 7 commenti 3 reazioni 0 assegnatari Vedi su GitHub
investigation needed
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.