danielgtaylor / danielgtaylor/python-betterproto

Invalid Enum member names which contain the Enum name

Open
#603 3 comments 0 reactions 0 assignees View on GitHub
compiler-bug
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

### Summary

2.0.0b7 breaks enums with underscores in field names

### Reproduction Steps

Test proto definition, in `test.proto`:
```proto
syntax = "proto3";

package hello;

// Greeting represents a message you can tell a user.
message Greeting {
Risk risk = 1;
}

enum Risk {
LOW_RISK = 0;
HIGH_RISK = 1;
}
```

Protoc compiler invocation:
```bash
$ protoc -I . --python_betterproto_out=lib test.proto
```

### Expected Results

2.0.0b6 output (`lib/hello/__init__.py`):
```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: test.proto
# plugin: python-betterproto
# This file has been @generated

from dataclasses import dataclass

import betterproto

class Risk(betterproto.Enum):
LOW_RISK = 0
HIGH_RISK = 1

@dataclass(eq=False, repr=False)
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""

risk: "Risk" = betterproto.enum_field(1)
```

### Actual Results

2.0.0b7 output (`lib/hello/__init__.py`):
```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: test.proto
# plugin: python-betterproto
# This file has been @generated

from dataclasses import dataclass

import betterproto

class Risk(betterproto.Enum):
_ = 0
_ = 1

@dataclass(eq=False, repr=False)
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""

risk: "Risk" = betterproto.enum_field(1)

```

### System Information

* Protoc version: libprotoc 27.3
* Python version: Python 3.11.7
* Betterproto version:
```
Name: betterproto
Version: 2.0.0b7
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: danielgtaylor@gmail.com
License: MIT
Location: /Users/connor/Code/tests/test070/.venv/lib/python3.11/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by:
```

### Checklist

- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.