danielgtaylor / danielgtaylor/python-betterproto

Nested packages causes invalid imports

Đang mở
#238 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
compiler-bug
Ngôn ngữ chính
Python
Star
1.8k
Fork
234
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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__`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Tái hiện vấn đề bằng lệnh protoc được hiển thị và kiểm tra các tệp đã tạo Foo/__init__.py và Foo/Example/__init__.py. Theo dõi cách message Bar đã import được phân giải trong quá trình tạo; hoàn tất khi đầu ra của package lồng nhau chứa một import hợp lệ cho Bar và các tệp đã tạo biên dịch thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.