danielgtaylor / danielgtaylor/python-betterproto
ImportError: cannot import name for ellipsis imports
- Langage dominant
- Python
- Étoiles
- 1.8k
- Forks
- 234
- Métriques de merge des PR
- Aucune PR mergée en 30 j
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.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Reproduisez le problème avec Content.proto et Detection.proto à l’aide de la commande protoc indiquée, puis inspectez les imports générés dans lib/My/Content/__init__.py. Suivez la manière dont le générateur choisit les niveaux d’import relatif pour MyContentContentType et MyDetectionDetectionGender. C’est terminé lorsque l’import de Content depuis lib.My réussit sans ImportError ni tentative d’import relatif au-delà du paquet de niveau supérieur.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100