danielgtaylor / danielgtaylor/python-betterproto

Namespaced enums yield incorrectly generated code

Offen
#197 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
compiler-bug
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Given following proto file

```
syntax = "proto3";
package namespaced_enum;

message ns { enum Type {
NONE = 0;
option_one = 1;
}}

message Msg {
ns.Type t = 1;
}
```

The command `python -m grpc_tools.protoc -I . --python_betterproto_out=lib ./test.proto` generates following code:

```py
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: proto/test.proto
# plugin: python-betterproto
from dataclasses import dataclass

import betterproto

from .namespaced_enum import ns

class NsType(betterproto.Enum):
NONE = 0
option_one = 1

@dataclass
class Ns(betterproto.Message):
pass

@dataclass
class Msg(betterproto.Message):
t: ns.Type = betterproto.enum_field(1)
```

It contains line `from .namespaced_enum import ns` and later on uses this as type `t: ns.Type = betterproto.enum_field(1)` instead of `NsType`

---
Python 3.8.2
betterproto 1.2.5
grpcio_tools 1.34.1

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Reproduce the issue with the provided test.proto and python -m grpc_tools.protoc command, then trace how the generator builds imports and enum type annotations. Done means the generated Msg field refers to the generated NsType enum rather than ns.Type, with a regression test covering this namespaced enum case.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.