On Thu, Jul 16, 2020, at 02:13, Stephen J. Turnbull wrote:
> Michael A. Smith writes:
>
> > It seems to me that obj.encode("json") and str.decode("json"), for example,
> > would be a powerful feature,
>
> This idea comes up a lot in various forms. The most popular lately is
> an optional __json__ dunder, which really would avoid the complication
> of working with custom JSONEncoders. That hasn't got a lot of takeup,
> though. Perhaps we could broaden the appeal by generalizing it to
> obj.__serialize__(protocol='json'), but that looks like overengineering
> to me.
This kind of thing [especially having objects directly call their referenced
objects' serialize methods rather than calling back to some other method to
serialize them] seems like it would limit the ability of the protocol to handle
with serialization formats that do anything to handle recursive or shared
references. Particularly if we're serious about Pickle not being a viable
foundation for secure deserialization, I think a new serialization protocol
needs to be flexible enough to handle these cases.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/CPOPVGEWL2RH6YUUFXO5U6IB5647DYEH/
Code of Conduct: http://python.org/psf/codeofconduct/