eliot icon indicating copy to clipboard operation
eliot copied to clipboard

Allow multiple types and serializers in `fields()`

Open itamarst opened this issue 10 years ago • 2 comments
trafficstars

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.

itamarst avatar Mar 17 '15 21:03 itamarst

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.

itamarst avatar Mar 17 '15 21:03 itamarst

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?

jonathanj avatar Mar 18 '15 12:03 jonathanj