danielgtaylor / danielgtaylor/python-betterproto

ImportError: cannot import name for ellipsis imports

Abierto
#178 7 comentarios 3 reacciones 0 asignados Ver en GitHub
investigation needed
Lenguaje dominante
Python
Estrellas
1.8k
Forks
234
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Reproduce el problema con Content.proto y Detection.proto usando el comando protoc mostrado y, a continuación, inspecciona los imports generados en lib/My/Content/__init__.py. Sigue cómo el generador elige los niveles de importación relativa para MyContentContentType y MyDetectionDetectionGender. Se considera terminado cuando importar Content desde lib.My funciona sin ImportError ni un intento de importación relativa más allá del paquete de nivel superior.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.