Skip to content

Enum Prefix is not stripped #174

@bschug

Description

@bschug

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions