Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Double underscore breaks existing code in betterproto v2/master

Aperta
#627 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Inizia eseguendo il comando grpc_tools.protoc segnalato su src/test.proto e verifica che field__json venga generato come field_json. Quindi traccia la gestione dei nomi dei campi Python di betterproto v2 coinvolta nella generazione. Il lavoro è completato quando il dataclass generato conserva field__json e la sua rappresentazione come dizionario/JSON rimane coerente con il nome originale del campo proto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
Summary

Double underscore breaks existing code

Reproduction Steps

When we try compiling the following proto-file, the field field__json becomes field_json

syntax = "proto3";
package test;

message TestMessage {
  string field__json = 1;
}
@dataclass(eq=False, repr=False, config={"extra": "forbid"})
class TestMessage(betterproto.Message):
    field__json: str = betterproto.string_field(1)
 python -m grpc_tools.protoc --python_betterproto_opt=pydantic_dataclasses --python_betterproto_out=src -Isrc src/test.proto
Expected Results

If we build the same code with betterproto v1, or with the standard compiler (python -m grpc_tools.protoc --python_out=src --pyi_out=src src/test.proto) the field name will remain unchanged.

Not only does this break current code, but this will also impact how a dict/JSON is being generated based on the data class/structure.

I would imagine this behaviour as unwanted and if we want to sanitize filed name, I think it would be better to do in the original proto-file (e.g. using tools like buf).

Actual Results

above

System Information
protoc --version; python --version; poetry run pip show betterproto
libprotoc 27.3
zsh: command not found: python
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/mikhailgalanin/Library/Caches/pypoetry/virtualenvs/betterproto-repro-O0YfRvug-py3.12/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: betterproto-repro
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.
Lingua principale
Python
Stelle
1.8k
Fork
235
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di danielgtaylor/python-betterproto

Tutte le issue di danielgtaylor/python-betterproto

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.