danielgtaylor / danielgtaylor/python-betterproto
Nested packages causes invalid imports
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 234
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
Compilation of proto files using 2.0.0b3
```sh
protoc -I . --python_betterproto_out=prototest base.proto example.proto
```
```proto
# base.proto
syntax = "proto3";
package Foo;
message Bar {
string value = 1;
}
```
```proto
# example.proto
syntax = "proto3";
import "base.proto";
package Foo.Example;
message Example {
Bar value = 1;
}
```
returns `Foo/__init__.py`
```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: base.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
from betterproto.grpc.grpclib_server import ServiceBase
@dataclass(eq=False, repr=False)
class Bar(betterproto.Message):
value: str = betterproto.string_field(1)
```
`Foo/Example/__init__.py`
```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
from betterproto.grpc.grpclib_server import ServiceBase
@dataclass(eq=False, repr=False)
class Example(betterproto.Message):
value: "__FooBar__" = betterproto.message_field(1)
from ... import FooBar as __FooBar__
```
The last import in `Foo/Example/__init__.py` is invalid, since there is no `FooBar` module. It probably should have been `from Foo import Bar as __FooBar__`.
Guía de contribución
Línea de trabajo
Reproduce the issue with the shown protoc command and inspect the generated Foo/__init__.py and Foo/Example/__init__.py files. Trace how the imported Bar message is resolved during generation; done means the nested package output contains a valid import for Bar and the generated files compile successfully.
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
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100