-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
Pythonization of enum names causes enum variables to become "_" (a single underscore), which makes generated files unusable
Reproduction Steps
I had the above issue with an enum similar to the below enum, which would generate code that would end up being unusable:
enum HadCoffee {
UNKNOWN_HAD_COFFEE = 0; // -> "_"
NO_HAD_COFFEE = 1; // -> "_"
HAD_COFFEE = 2; // -> "_"
}Resulting generated enum code:
class HadCoffee(betterproto2.Enum):
_ = 0
_ = 1
_ = 2This code will not import, as it has a variable name conflict between all the underscores. Based on what I can tell, the error seems to be caused by the way that the enum names are transformed/pythonized by the compiler.
Expected Results
class HadCoffee(betterproto2.Enum):
UNKNOWN_HAD_COFFEE = 0
NO_HAD_COFFEE = 1
HAD_COFFEE = 2Actual Results
class HadCoffee(betterproto2.Enum):
_ = 0
_ = 1
_ = 2System Information
protoc --version: libprotoc 31.1
python --version: Python 3.13.1
pip show betterproto2:
Name: betterproto2
Version: 0.7.0
Summary: A better Protobuf / gRPC generator & library
Home-page:
Author:
Author-email: Adrien Vannson <adrien.vannson@protonmail.com>, "Daniel G. Taylor" <danielgtaylor@gmail.com>
License:
Location: /Users/oduggin/Documents/services/cloudautomation/venv/lib/python3.13/site-packages
Requires: python-dateutil, typing-extensions
Required-by: betterproto2_compiler
Checklist
- I have searched the issues for duplicates.
- I have shown the entire traceback, if possible.
- I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto, if possible.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working