Open justanr opened 6 years ago
It will be very helpful for using marshmallow-enum. Because now there are no way to register EnumField for all enums
You wouldn't want to register one field for so enums since dealing with the serialization process involves looking at that particular enum and its values.
We could look at adding an enum registration helper. I'd like to avoid bringing in ma_enum if possible but enough people have requested it that it might be worth it.
dealing with the serialization process involves looking at that particular enum and its values
For dealing with it BaseConverter should pass typehint to field_constructor (according FieldFactory should accept typehint argument). Together with parent class registration it allow to register EnumField for all enums. Also it allow base class registration for many other cases, where FieldFactory can produce proper field for concrete base class implementation. Cons of this proposal is possible backward incompatibility issue
Hmm. I'd be willing to look at a PoC for that.
As for this proposal in general, my current line of thinking is to use functools.singledispatch
since it already exists and deals with quite a few corner cases but I'm not 100% sold on that yet
ala singledispatch
If I have
ClassA
registered with a schema, then I should be able to useClassB(ClassA)
in a declaration and this lib will see that whileClassB
itself isn't registered it's parent is and use that schema.Edge Case:
what do now? My knee jerk is to use
A
's schema since it's first in the MRO order.Additionally, if no schema is found for the child class, should the chosen schema be pushed into the registry as the schema for that type?