-
Notifications
You must be signed in to change notification settings - Fork 229
Invalid Enum member names which contain the Enum name #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Regression caused by the last change to https://github.com/danielgtaylor/python-betterproto/blob/bd7de203e16e949666b2844b3dec1eb7c4ed523c/src/betterproto/compile/naming.py |
Would be fixed by #589 though I'll have a think about whether to change the function t ostrip the name |
Smart-stripping by default may lead to confusion, and should be mentioned on the homepage/docs. Testsdef pythonize_enum_member_name(name: str, enum_name: str) -> str:
enum_name = casing.snake_case(enum_name).upper()
find = name.find(enum_name)
if find != -1:
name = name[find + len(enum_name) :].strip("_")
return casing.sanitize_name(name) >>> pythonize_enum_member_name("UNKNOWN_COLOR", "Color")
'_'
>>> pythonize_enum_member_name("SWIFTUI", "UI")
'_'
>>> pythonize_enum_member_name("MONGODB", "DB")
'_'
>>> pythonize_enum_member_name("BLACKBIRD", "Bird")
'_'
>>> pythonize_enum_member_name("SUNFLOWER", "Flower")
'_'
>>> pythonize_enum_member_name("FOOTBALL", "Ball")
'_'
>>> pythonize_enum_member_name("SOCCER_BALL", "Ball")
'_'
>>> pythonize_enum_member_name("EMPLOYEE_ID_NUMBER", "ID")
'NUMBER'
>>> pythonize_enum_member_name("WIFI_NETWORK", "Net")
'WORK'
>>> pythonize_enum_member_name("OAUTH_LOGIN", "Auth")
'LOGIN'
>>> pythonize_enum_member_name("KEYWORDS", "Word")
'S'
# This one is OK:
>>> pythonize_enum_member_name("X11_METHOD_NONE", "X11Method")
'NONE'
>>> pythonize_enum_member_name("A11Y_METHOD_NONE", "A11YMethod")
'A11Y_METHOD_NONE'
>>> pythonize_enum_member_name("DTYPE_NONE", "DType")
'DTYPE_NONE' WarningsPerhaps produce a warning if the input may cause issues or if the output is
|
Summary
2.0.0b7 breaks enums with underscores in field names
Reproduction Steps
Test proto definition, in
test.proto
:Protoc compiler invocation:
$ protoc -I . --python_betterproto_out=lib test.proto
Expected Results
2.0.0b6 output (
lib/hello/__init__.py
):Actual Results
2.0.0b7 output (
lib/hello/__init__.py
):System Information
Checklist
pip install -U --pre betterproto
, if possible.The text was updated successfully, but these errors were encountered: