danielgtaylor / danielgtaylor/python-betterproto

Fix for broken relative imports and missing betterproto_lib_google_protobuf

Open
#472 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.