Open chuckwondo opened 3 months ago
Hi there!
Just noticed this yesterday as well.
From what I can see ,this doesn't only affect the json
encoding.
This is an example of MsgPack acting the same way:
from msgspec.msgpack import decode, encode
from msgspec.structs import Struct
class User(Struct, tag=1, array_like=True):
username: str
is_admin: bool = False
class Comment(Struct, tag=2, array_like=True):
user: User
content: str
likes: int = 0
is_highlighted: bool = False
username = "ipseitas"
content = "Lovin' this lib, please add donations!"
comment = Comment(User(username), content)
commentlike = (2, (1, username), content)
>>> encode(comment)
... b"\x95\x02\x93\x01\xa8ipseitas\xc2\xd9&Lovin' this lib, please add donations!\x00\xc2"
>>> encode(commentlike)
... b"\x93\x02\x92\x01\xa8ipseitas\xd9&Lovin' this lib, please add donations!"
>>> decode(encode(commentlike), type=Comment) == comment
... True
Implementing fits the theme of being efficient that your package shines at. If this helps you deliver, please add donation #542. I'll gladly transfer some of the time your lib saved me and am sure others would as well :)
Description
When setting both
omit_defaults
andarray_like
toTrue
, defaults are not omitted.For example, without
array_like=True
:Performing a roundtrip works as expected:
However, adding
array_like=True
to thePosition
definition above causes rountripping to fail: