danielgtaylor / danielgtaylor/python-betterproto

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

オープン
#657 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug investigation needed
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、報告された protoc コマンドをメッセージ example.proto に対して実行し、生成されたフィールド名を期待される出力と比較します。protobuf のフィールド名を Python の名前に変換するジェネレーターのエントリーポイントを追跡します。c2s のようなフィールドが c2_s になるのではなく c2s のままになり、プロジェクトの既存テストに適切な場所があれば回帰テストによるカバレッジも追加されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。