You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I wonder if it is possible, to serialize a class to a dict using a generator.
It could help to reduce memory allocations when serializing dataclasses with __slots__.
The text was updated successfully, but these errors were encountered:
nmoreaud
changed the title
Is it possible to serialize a class without instanciating a dict (ie: use a generator)
Is it possible to serialize a class without instanciating a dict? (ie: use a generator)
Aug 11, 2023
No, that is not currently possible. isinstance(obj, dict) must be True in order for it to serialize as a JSON object. I think it's unlikely to make all that much of a difference, but you're welcome to try it. If you can show it does improve performance in a meaningful way and provide a PR with tests then I'd be happy to review it.
Hello,
I wonder if it is possible, to serialize a class to a dict using a generator.
It could help to reduce memory allocations when serializing dataclasses with
__slots__
.I think about something like this:
The text was updated successfully, but these errors were encountered: