danielgtaylor / danielgtaylor/python-betterproto
Fix for broken relative imports and missing betterproto_lib_google_protobuf
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Rechercherichtung
Beginne damit, ServiceMethodCompiler.__post_init__, output_package.imports und den imports-Abschnitt des Templates nachzuverfolgen, und vergleiche anschließend die Behandlung von Eingabe- und Ausgabemessage-Typen. Reproduziere nach Möglichkeit die Fehler in den generierten Dateien für google.protobuf und relative imports und berücksichtige die im Issue vorgeschlagene Behandlung von Optional-Imports; als erledigt gilt die Aufgabe, wenn beide Importformen zuverlässig generiert werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100