Skip to content
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

Invalid Enum member names which contain the Enum name #603

Open
3 tasks done
connorbrinton opened this issue Aug 29, 2024 · 2 comments
Open
3 tasks done

Invalid Enum member names which contain the Enum name #603

connorbrinton opened this issue Aug 29, 2024 · 2 comments
Labels
compiler-bug The compiler is broken

Comments

@connorbrinton
Copy link

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.
@connorbrinton connorbrinton added bug Something isn't working investigation needed labels Aug 29, 2024
@Gobot1234 Gobot1234 added compiler-bug The compiler is broken and removed bug Something isn't working investigation needed labels Aug 31, 2024
@Gobot1234
Copy link
Collaborator

Gobot1234 commented Aug 31, 2024

@Gobot1234
Copy link
Collaborator

Would be fixed by #589 though I'll have a think about whether to change the function t ostrip the name

@Gobot1234 Gobot1234 changed the title Invalid Enum member names with underscores Invalid Enum member names which contain the Enum name Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-bug The compiler is broken
Projects
None yet
Development

No branches or pull requests

2 participants