Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Unexpected behaviour with explicitly setting seconds = 0 with timedelta and using to_dict

Đang mở
#649 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu bằng cách xác định phần xử lý timedelta được Message.to_dict sử dụng và tái hiện hai ví dụ từ issue trên Python 3.11. Kiểm tra rằng một timedelta bằng không giây được cung cấp tường minh vẫn được giữ nguyên trong dictionary, với đầu ra khớp với trường hợp mong đợi {'timeout': '0s'}.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug investigation needed
Summary

When using timedelta with explicitly setting the seconds to 0 the output is empty instead of being explicitly set

Reproduction Steps
>>> from datetime import timedelta
>>> from dataclasses import dataclass
>>> import betterproto
>>> 
>>> @dataclass(eq=False, repr=False)
... class TestTimeout(betterproto.Message):
...     timeout: timedelta = betterproto.message_field(1)
... 
>>> TestTimeout(timeout=timedelta(seconds=0)).to_dict()
{}
>>> from datetime import timedelta
>>> from dataclasses import dataclass
>>> import betterproto
>>> 
>>> @dataclass(eq=False, repr=False)
... class TestTimeout(betterproto.Message):
...     timeout: timedelta = betterproto.message_field(1)
... 
>>> TestTimeout(timeout=timedelta(seconds=1)).to_dict()
{'timeout': '1.000s'}
Expected Results

Output expected to be {'timeout': '0s'}

Actual Results

Output is an empty dict {}

System Information

betterproto==2.0.0b6

python 3.11

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.
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của danielgtaylor/python-betterproto

Tất cả issue của danielgtaylor/python-betterproto

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.