danielgtaylor / danielgtaylor/python-betterproto

Fix for broken relative imports and missing betterproto_lib_google_protobuf

オープン
#472 コメント 2 件 リアクション 3 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

The issue affects both relative imports and google.protobuf imports, but is not 100% reproducible.

My working theory is that for service method input types `output_package.imports` sometimes populates too late to be included in the imports section of a generated file. The list is populated only when template is compiled with `method.py_input_message_param` which comes way after the import section.

On the contrary, imports for output types are figured out before template compilation in `ServiceMethodCompiler:__post__init__` by using `self.py_output_message_type`

Fix is to add
```
if "Optional" in self.py_input_message_type:
self.output_file.typing_imports.add("Optional")
```

I have only checked it with google.protobuf types, but I suspect that relative imports behave no different and this issue is related to #441

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず ServiceMethodCompiler.__post_init__、output_package.imports、および template の imports セクションを追跡し、その後、入力メッセージ型と出力メッセージ型の処理を比較します。可能であれば、google.protobuf と相対 imports に関する生成ファイルの失敗を再現し、issue で提案されている Optional の import 処理を検討します。両方の import 形式が確実に生成されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。