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

Enum Prefix is not stripped

Open bschug opened this issue 4 years ago • 4 comments

According to the Style Guide, protobuf enums should have the enum name as a prefix for all enum values, to avoid naming conflicts in languages like C, where all values from all enums are in the global namespace. Protobuf compilers for languages with scoped enums like C# will strip these prefixes if they match the enum name. Since enums in betterproto are scoped as well, these prefixes should be stripped.

Example:

enum ArithmeticOperator {
    ARITHMETIC_OPERATOR_NONE = 0;
    ARITHMETIC_OPERATOR_PLUS = 1;
    ARITHMETIC_OPERATOR_MINUS = 2;
}

should become

class ArithmeticOperator(betterproto.Enum):
    NONE = 0
    PLUS = 1
    MINUS = 2

so that we can use it as

if something.operator == ArithmeticOperator.PLUS:
     do_addition()

instead of

if something.operator == ArithmeticOperator.ARITHMETIC_OPERATOR_PLUS:
    do_addition()

bschug avatar Nov 24 '20 16:11 bschug

I'm happy to make a PR for this

Gobot1234 avatar Nov 24 '20 18:11 Gobot1234

This should be fixed by #187 :)

Gobot1234 avatar Dec 18 '20 12:12 Gobot1234

This his a huge deal for my team. Can we have an ETA?

Thanks the the meantime I've been using your branch @Gobot1234 with no issues

cigani avatar Apr 07 '21 10:04 cigani

Should be soon hopefully I just needed a re-review from Nat.

Gobot1234 avatar Apr 07 '21 11:04 Gobot1234