Provide a way to use a custom base class instead of betterproto.Message
还没有人认领这个 Issue。
评估
调研方向
先从编译器 CLI 参数的设计以及 issue 中提到的 init Jinja 模板开始,然后检查生成的消息类如何选择 betterproto.Message,以及生成的 init.py 文件如何写入。完成的标准是:为生成的消息使用已配置的自定义基类,并且可以通过生成的包结构导入子包。
由索引模型根据 Issue 内容生成。
描述
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
- betterproto lacks a way to customize the base class for the generated messages classes.
- 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:
- 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.MyMessageBaseClassto use in the init jinja template. - import subpackages (if any) in the
__init__.pygenerated 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).
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 235
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielgtaylor/python-betterproto 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 15/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 42/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 45/100
-
bug investigation needed
难度 4/5 3-5 天 新手友好度 38/100
danielgtaylor/python-betterproto#676 · 3 条评论 ·
查看 danielgtaylor/python-betterproto 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/sample-per-model-bedrock#464 ·
维护者通常 1 天内回复
-
lesson-submission pending-review
难度 2/5 1-3 小时 新手友好度 67/100
Ikalus1988/MisakaNet#3789 ·
维护者通常 1 天内回复
-
Python Volcengine provider returns failures instead of raising them可能已有人在做 @Ricardo-M-L 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
agent-infra/sandbox#248 ·
-
[Bug] cloud JSON directory loading assumes a Key field in fsspec listings可能已有人在做 @Ricardo-M-L 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
hiyouga/LlamaFactory#10910 ·
维护者通常 1 天内回复
-
Bundled uv is never updated and trusts the compromised eMudhra certificates可能已有人在做 @FabienDanieau 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100