Provide a way to use a custom base class instead of betterproto.Message
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với thiết kế đối số CLI của compiler và template Jinja init được đề cập trong issue, sau đó kiểm tra cách các lớp message được sinh ra chọn betterproto.Message và cách các tệp init.py được sinh ra được ghi. Công việc được xem là hoàn tất khi một lớp cơ sở tùy chỉnh đã cấu hình được sử dụng cho các message được sinh ra và các subpackage có thể được import thông qua cấu trúc package được sinh ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 235
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của danielgtaylor/python-betterproto
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
-
bug investigation needed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
bug investigation needed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
bug investigation needed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
danielgtaylor/python-betterproto#676 · 3 bình luận ·
Tất cả issue của danielgtaylor/python-betterproto
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
changelog investigate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ramnes/notion-sdk-py#423 ·
-
type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày