danielgtaylor / danielgtaylor/python-betterproto

In generated field name, an undescore is introduced after a number

Open
#657 1 comment 0 reactions 0 assignees View on GitHub
bug investigation needed
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

### Summary

Underscore is added after a number in the field name, e.g. `c2s` becomes `c2_s`.

### Reproduction Steps

```proto
syntax = "proto3";

message Example {
string c2s = 1;
}
```

```bash
protoc --python_betterproto_out=lib example.proto
```

### Expected Results

Expecting `c2s`.

```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
# This file has been @generated

from dataclasses import dataclass

import betterproto

@dataclass(eq=False, repr=False)
class Example(betterproto.Message):
c2s: str = betterproto.string_field(1)
```

### Actual Results

Generates `c2_s` instead.

```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
# This file has been @generated

from dataclasses import dataclass

import betterproto

@dataclass(eq=False, repr=False)
class Example(betterproto.Message):
c2_s: str = betterproto.string_field(1)
```

### System Information

libprotoc 27.1
Python 3.8.20
Name: betterproto
Version: 2.0.0b7
Location: /Users/.../demo/.venv/lib/python3.8/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: demo

### 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.