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 <greg.ew...@canterbury.ac.nz> > Subject: [Python-ideas] Re: Improvement: __json__ > To: python-ideas@python.org > Message-ID: <e70016ba-5419-e252-d7bd-9705dbebf...@canterbury.ac.nz> > 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 > serialized. > > 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. > > -- > Greg > >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ISSUQVYI5OYYXKELUNCD5YCEDZ75LCEB/ Code of Conduct: http://python.org/psf/codeofconduct/