hydration icon indicating copy to clipboard operation
hydration copied to clipboard

Enable parameterless deserialization

Open shustinm opened this issue 3 years ago • 0 comments

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.

shustinm avatar May 02 '21 22:05 shustinm