Skip to content

Enum with reserved word (None) clashes with python #302

Closed
@ikelos

Description

@ikelos

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions