As the author of one of these third-party libraries, I feel like I can contribute to this discussion. It can indeed be done very elegantly with type annotations, and it should for sure be left to the ecosystem.
The only things we need from core Python are good tools for dealing with run-time type information. For example, singledispatch doesn't really work with types (i.e. Optionals, Unions, Sequences as opposed to actual classes), but all of that can be worked around.
In my experience, runtime type information is extremely useful exactly in cases of deserialization, and for big projects starts being useful much before the type information starts being useful in a static analysis context.
From: Greg Ewing email@example.com Subject: [Python-ideas] Re: Improvement: __json__ To: firstname.lastname@example.org Message-ID: email@example.com Content-Type: text/plain; charset=utf-8; format=flowed
On 7/04/20 4:57 am, Wes Turner wrote:
Python object > JSON > object requires type information to be
Not necessarily -- Java's json library uses reflection on compile time type information to deserialise json into an object hierarchy. You tell it the class corresponding to the top level and it figures out the rest.
Something similar could be done in Python using type annotations.