[Python-ideas] Re: Proposal for __encode__ method for json encoder and dataclasses

2020-12-10 Thread Christopher Barker
I'm a bit confused here. there have been multiple discussions on this list about having a magic methods (maybe __json__) that could be called by the json module (or any other) -- so that objects could define for themselves how to be encoded as JSON. Is this the same idea? in which case, if you

[Python-ideas] Re: Proposal for __encode__ method for json encoder and dataclasses

2020-12-10 Thread Eric V. Smith
On 12/10/2020 10:08 AM, Eric V. Smith wrote: The dataclass metadata feature was added for this type of use, or at least experimenting with it: ... I realize this isn't helpful in general, where a dataclass is a member of another object hierarchy. But it could be leveraged by a

[Python-ideas] Re: Proposal for __encode__ method for json encoder and dataclasses

2020-12-10 Thread Eric V. Smith
On 12/9/2020 10:39 AM, Chris Angelico wrote: On Thu, Dec 10, 2020 at 12:38 AM sam bland wrote: In response to the additional work required to convert the new python dataclass using the json encoder I propose an __encode__ method that will be included in the default dataclass attributes. This

[Python-ideas] Re: Proposal for __encode__ method for json encoder and dataclasses

2020-12-09 Thread Chris Angelico
On Thu, Dec 10, 2020 at 12:38 AM sam bland wrote: > > In response to the additional work required to convert the new python > dataclass using the json encoder I propose an __encode__ method that will be > included in the default dataclass attributes. This would then be picked up by > the

[Python-ideas] Re: Proposal for __encode__ method for json encoder and dataclasses

2020-12-09 Thread Guido van Rossum
Maybe you could start by writing this as a separate decorator, to be applied on top of the data class decorator? On Wed, Dec 9, 2020 at 05:38 sam bland wrote: > In response to the additional work required to convert the new python > dataclass using the json encoder I propose an __encode__