typed_python
typed_python copied to clipboard
Allow types to specify the tags for their pieces during serialization
Our serialization library has a similar structure to protobuf - we want each field in a composite datastructure to have a field id that's stable over time as we change types so that objects serialized under old versions of the code can still be read and manipulated. Right now, we have no way of controlling this, so we're only stable if we append elements to a Tuple, NamedTuple, OneOf, or Alternative. We should have a syntax for explicitly setting these IDs.
I was thinking something like
OneOf(int, float) == OneOf({int: 0, float: 1})
for one of, and
NamedTuple(x=int, y=float) == NamedTuple(x=int, y=float).withTags(x=0, y=1)
Not sure what the best approach for alternatives and classes is yet.