python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Enum with reserved word (`None`) clashes with python

Open ikelos opened this issue 4 years ago • 1 comments

Hiya,

I've just started working with gather.town which provides a version 3 proto file. I had to remove the optional keywords (as best I can tell, they're somewhat unnecessary in proto3 files) and it all started generating fine. I found, however, that when importing the file that the following enum:

message EmoteEnum {
  enum ENUM {
    None = 0;
    Wave = 1;
    Heart = 2;
    PartyPopper = 3;
    ThumbsUp = 4;
    QuestionMark = 5;
    RaisedHand = 6;
  }
}

generates the following dataclass:

class EmoteEnumENUM(betterproto.Enum):
    None = 0
    Wave = 1
    Heart = 2
    PartyPopper = 3
    ThumbsUp = 4
    QuestionMark = 5
    RaisedHand = 6

which tries to assign to None. There doesn't appear to be a great mechanism for working around this automatically. The best I've found would be to append an _ and documenting that this would happen to any field name found in keyword.kwlist. There is a workaround for dataclasses-json, but obviously that's not a default package with python and doesn't look like a suitable solution to the issue...

ikelos avatar Dec 24 '21 11:12 ikelos

This is fixed by https://github.com/danielgtaylor/python-betterproto/pull/187

Gobot1234 avatar Dec 24 '21 11:12 Gobot1234