Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Invalid Enum member names which contain the Enum name

未关闭
#603 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
compilers

调研方向

使用 test.proto 定义和文档中的 protoc -I . --python_betterproto_out=lib test.proto 命令重现 issue。将生成的 lib/hello/__init__.py 与预期的 2.0.0b6 输出进行比较,重点关注 Risk 枚举成员。完成标准是 LOW_RISK 和 HIGH_RISK 等枚举名称得以保留,而不是变成 _。

由索引模型根据 Issue 内容生成。

描述

compiler-bug
Summary

2.0.0b7 breaks enums with underscores in field names

Reproduction Steps

Test proto definition, in test.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:

$ protoc -I . --python_betterproto_out=lib test.proto
Expected Results

2.0.0b6 output (lib/hello/__init__.py):

# 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):

# 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: [email protected]
License: MIT
Location: /Users/connor/Code/tests/test070/.venv/lib/python3.11/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by:
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.
主要语言
Python
星标
1.8k
派生
235
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

danielgtaylor/python-betterproto 的其他 Issue

查看 danielgtaylor/python-betterproto 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。