Would you generate a schema from the type annotations so that other languages can use the data?
I haven't done this yet, but it would be pretty cool.
> So, IMHO type annotations are not insufficient and thus redundant and not elegant.
you mean are not sufficient / or are insufficient?
But what is meant by "type annotations"? I'm using them via dataclasses -- really as a shorthand for assigning a type to every field -- the annotations are just a shorthand that auto-generates a schema, essentially.
x: A_Type = A_default
So now I know that this class has a field names x that is the type int. So I use that type for validation, and serialization / deserialization.
But if you mean "type annotations" in the sense of the types provided out of the box in the typing module and used by MyPy (so I've heard, never did it myself) -- no, they are not sufficient -- I need types that support my serialization / deserialization system, and my validation system. And I suppose we could have a standardized __json__ and __from_json__ protocol that I could use, but it seems a special case to me.
Note: I don't need to do anything special for types with standard json representation, but that's only the basics -- I end up using custom types for anything nested.
Christopher Barker, PhD
Python Language Consulting
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython