danielgtaylor / danielgtaylor/python-betterproto

datetime support in .from_dict()

Offen
#33 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug good first issue low priority small
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Good day, assuming I have
`d = {'date_of_birth': datetime.datetime(2000)}`
and a `proto` including
`date_of_birth: Timestamp`:
When `proto.from_dict(d)` is called, it assumes the value of date_of_birth is an ISO string and does not consider that it may already be a `datetime.datetime`

I refer to your `__init__.py` L799-803:
```
elif isinstance(v, datetime):
v = datetime.fromisoformat(
value[key].replace("Z", "+00:00")
)
setattr(self, field.name, v)
```
This should check if `value[key]` is already an instance of `datetime.datetime` and assign it directly, shouldn't it?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.