Closed sihrc closed 8 months ago
Datetimes without timezones encode as strings, since the msgpack
timestamp extension only represents datetimes with timezones.
When decoding, the decoder has no way to know that the value should be interpreted as a datetime
rather than a string unless you provide it a type annotation representing the expected schema.
In [1]: import datetime
In [2]: import msgspec
In [3]: dt = datetime.datetime.now()
In [4]: encoded = msgspec.msgpack.encode(dt)
In [5]: msgspec.msgpack.decode(encoded) # no type annotation
Out[5]: '2024-03-14T13:28:46.058671'
In [6]: msgspec.msgpack.decode(encoded, type=datetime.datetime) # with type annotation
Out[6]: datetime.datetime(2024, 3, 14, 13, 28, 46, 58671)
See the docs for more information.
Description
python==3.11.0rc1 msgspec==0.18.6
Maybe related to #534 ?