eliot
eliot copied to clipboard
Allow multiple types and serializers in `fields()`
It would be nice to be able to do something like:
fields(value=(None, str), another=int, also=serialize_with(repr))
I.e. allow not just single types with fields() but also multiple types and serializer functions.
Or perhaps instead of hacks like that for backwards compatibility just write a nicer replacement for fields? Maybe ActionType can grow a utility class method, say.
Indeed, I have found myself needing to declare a Field by hand because i wanted to allow None as a value, which was a bit annoying, it would be great if this were easier.
Is ActionType the right place for something like that, did you mean Field? It seems plausible one might want to use this with messages too. My personal preference is a free function over a class method.
What is the desired scope of this new field builder? Your example allows multiple types, single types and a serializer. What about single (or multiple) types with a custom serializer? Perhaps Field should be simpler to instantiate?