hydration
hydration copied to clipboard
Enable parameterless deserialization
Is your feature request related to a problem? Please describe.
Calling __init__
creates API constraints on the user.
Describe the solution you'd like
Call cls.__new__
directly in the from_bytes
implementation, similarly to pickle. I feel like this is the most natural solution to this problem given the nature of the library.
Describe alternatives you've considered
Currently, StructMeta
overrides the from_bytes
and from_stream
methods with ones that have injected arguments, meaning that there's still API for deserializing non default-constructable structs. The issue with this method is that deserializing into a struct still requires initializing one with fake arguments.
Another solution is to either force or recommend users to implement their own classmethods for creating objects instead of custom constructors.