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

Provide a way to use a custom base class instead of betterproto.Message

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Inizia con la progettazione dell’argomento della CLI del compilatore e del template Jinja init menzionato nell’issue, quindi esamina come le classi dei messaggi generate scelgono betterproto.Message e come vengono scritti i file init.py generati. Il lavoro è completato quando per i messaggi generati viene utilizzata una classe base personalizzata configurata e i sottopackage possono essere importati tramite la struttura dei package generata.

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

Descrizione

enhancement
Summary

Allow to customize the base class, to provide helper methods and enrich the model

What is the feature request for?

The core library

The Problem

We developed an internal library on top of betterproto and pika rabbitmq packages.
During development, we found that

  1. betterproto lacks a way to customize the base class for the generated messages classes.
  2. it's not possible to access message classes in the following way:
import mylib as ml

ml.messages.device.settings.ConfigureDevice(*args)
The Ideal Solution

To ease all above, would be handy to provide:

  1. A way to use a MyMessageBaseClass(betterproto.Message) as base class for generated messages. This would probably be a new cli argument for the compiler e.g. --base_class=mylib.base.MyMessageBaseClass to use in the init jinja template.
  2. import subpackages (if any) in the __init__.py generated files.
The Current Solution

To enrich the classes with helper methods and to override some methods of the betterproto.Message class, we first patched the generated classes, to add mixins and overridden methods at runtime.

This is working well, but Python IDEs' support is limited.

We solved some of the issues above by adding a post compilation step at installation time, to add code to the betterproto generated files.
During this step, we also add subpackages imports to __init__.py files, to access messages conveniently using the fqn (see point 2. of the issue).

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.