danielgtaylor / danielgtaylor/python-betterproto
Unexpected behaviour with explicitly setting seconds = 0 with timedelta and using to_dict
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### Summary
When using timedelta with explicitly setting the seconds to 0 the output is empty instead of being explicitly set
### Reproduction Steps
```python3
>>> 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
- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.
Beitragsleitfaden
Rechercherichtung
Beginne damit, die für Message.to_dict verwendete timedelta-Behandlung zu lokalisieren und die beiden Beispiele aus dem Issue unter Python 3.11 zu reproduzieren. Überprüfe, dass eine explizit angegebene timedelta von null Sekunden im Dictionary erhalten bleibt und die Ausgabe dem erwarteten Fall {'timeout': '0s'} entspricht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100