Provide explicit type hints and pydantic validation for robust usage
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 bằng cách xem xét openpaygo/models.py và các phần triển khai hiện có trong openpaygo/token_encode.py, openpaygo/token_decode.py, metrics_request.py, metrics_response.py và token_shared.py. Kiểm tra các bài kiểm thử tích hợp, hiện đang báo cáo 80 bài kiểm thử đạt. Công việc được xem là hoàn tất khi các hàm được liệt kê có chỉ dẫn kiểu rõ ràng, đầu vào không hợp lệ được xác thực bằng các mô hình Pydantic đã nêu và bộ kiểm thử tiếp tục chạy thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description:
Hi team! Thanks for building such an awesome library for the OpenPAYGO ecosystem.
Expected Behavior:
When using the OpenPAYGO library in modern Python backend applications (like FastAPI servers or typing-heavy codebases), developers expect:
- Clear type definitions showing what arguments standard functions (like
decode_tokenorMetricsRequestHandler) accept and return. - When processing JSON or dictionaries from devices, malformed data should raise explicit parsing/validation errors before reaching deep token logic.
Current Behavior:
Currently, functions like decode_token and MetricsRequestHandler rely on loose dictionaries and typeless signatures. Passing incorrect types or malformed historical data can trigger cryptic KeyError or ValueError, making debugging difficult.
Proposed Solution:
Add explicit Python typing (typing.Dict, typing.Optional, etc.) to method signatures across:
openpaygo/token_encode.pyopenpaygo/token_decode.pymetrics_request.py/metrics_response.py
Additionally, leverage Pydantic models to automatically validate and parse input data, stripping invalid or unexpected fields.
Implementation Notes:
-
Created
openpaygo/models.pywith Pydantic models:MetricsDataFormatMetricsRequestDataMetricsHistoricalDataStep
-
Functions in
metrics_request.pyandmetrics_response.pynow cast dictionaries into Pydantic models. -
Core files (
token_shared.py,token_encode.py,token_decode.py) updated with type hints. -
Integration tests run successfully with all 80 tests passing.
Benefits:
- Improved type safety and clearer function signatures.
- Automatic input/output validation reduces runtime errors.
- Easier debugging and maintenance for developers.
- Ngôn ngữ chính
- Python
- Star
- 15
- Fork
- 15
- 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
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 EnAccess/OpenPAYGO-python
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
EnAccess/OpenPAYGO-python#25 ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
EnAccess/OpenPAYGO-python#24 ·
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
EnAccess/OpenPAYGO-python#22 ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
EnAccess/OpenPAYGO-python#21 ·
-
documentation enhancement good first issue hacktoberfest help wanted
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
EnAccess/OpenPAYGO-python#15 ·
Tất cả issue của EnAccess/OpenPAYGO-python
Issue tương tự
-
pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pydantic/pydantic-ai#8843 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change enhancement server
Độ 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
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
sktime/sktime#11310 · 1 bình luận ·
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 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày